gpt4 book ai didi

ruby-on-rails - 无法为 ActionMailer::Base 找到 Rails 3 "The action ' 方法'

转载 作者:行者123 更新时间:2023-12-04 05:34:28 25 4
gpt4 key购买 nike

无法在 rails 3. 中发送邮件。在浏览器中显示以下消息。

Unknown action

The action 'method' could not be found for ActionMailer::Base

这是我写的代码。
  • Notifier.rb
  • class Notifier < ActionMailer::Base 
    default :from => "xxxxx@gmail.com"
    default_url_options[:host] = "localhost.com:3000"



    def welcome_email(user)

    @user_email = user
    @url = root_url
    mail(:to => user.email,
    :subject => "Welcome to the site")
    end
    end


    2.UsersController.rb
     Notifier.welcome_email(@user).deliver
  • application.rb
  • config.action_mailer.deliver_method = :smtp
    config.action_mailer.smtp_settings = {
    :address => "smtp.gmail.com",
    :port => 587,
    :domain => 'xxxxxxx.com',
    :user_name => 'xxxx@gmail.com',
    :password => 'xxxx',
    :authentication => 'plain',
    :enable_starttls_auto => true
    }

    这是日志消息

    AbstractController::ActionNotFound (The action 'method' could not be found for ActionMailer::Base):
    app/mailers/notifier.rb:1:in <top
    (required)>'

    app/controllers/users_controller.rb:17:in
    create'

    Rendered C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.5/lib/action_dispatch/middleware/templates/rescues/unknown_action.erb within rescues/layout (0.0ms)

    最佳答案

    它是

    config.action_mailer.delivery_method

    不是
    config.action_mailer.deliver_method

    .

    我今天碰巧在我的配置中犯了同样的错字。

    关于ruby-on-rails - 无法为 ActionMailer::Base 找到 Rails 3 "The action ' 方法',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5350146/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com