Rails 3“操作”方法“无法找到 ActionMailer::Base”
无法在 Rails 3 中发送邮件,在浏览器中显示以下消息。
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"
defwelcome_email(用户)
@用户电子邮件=用户
@url = root_url
邮件(:to => user.email,
:主题=> “欢迎来到该网站”)
结尾
结尾
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::Base):
app/mailers/notifier.rb:1:in创建'
'
应用程序/控制器/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_action.erb 在救援/布局内(0.0ms)
Unable to send mail in rails 3. showing following message in browser.
Unknown action
The action 'method' could not be found for ActionMailer::Base
Here is the code I wrote.
- 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 }
Here is the log messages
AbstractController::ActionNotFound
(The action 'method' could not be
found for ActionMailer::Base):
app/mailers/notifier.rb:1:in<top
create'
(required)>'
app/controllers/users_controller.rb:17:inRendered
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它
不是
。
我今天碰巧在我的配置中犯了同样的错字。
It's
not
.
I happened to make the same typo in my configuration today.