无法使用rails 3发送邮件3.在浏览器中显示以下消息。Rails 3“无法找到ActionMailer :: Base的动作'方法'
Unknown action
The action 'method' could not be found for ActionMailer::Base
这是我写的代码。
- Notifier.rb
class Notifier < ActionMailer::Base
default :from => "[email protected]"
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 => '[email protected]',
:password => 'xxxx',
:authentication => 'plain',
:enable_starttls_auto => true
}
这里是日志消息
一个AbstractController :: ActionNotFound (动作 '方法' 不能 找到的ActionMailer ::碱):
应用程序/邮寄者/通知。 RB:1:<top (required)>'
创建”
app/controllers/users_controller.rb:17:in渲染 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.5/lib/action_dispatch/middleware/templates/rescues/unknown_actio n.erb 内救援/布局(0.0ms)
请查看http://asciicasts.com/episodes/206-action-mailer-in-rails-3。它对我有好处 – 2011-03-18 10:17:34