如何使用preview_enabled = true在rails 4.2上配置动作邮件程序

时间:2014-12-04 13:11:06

标签: actionmailer ruby-on-rails-4.2

由于rails 4.2现已发布,我想在暂存时将邮件预览添加到我的项目中。在此之后我会把这段代码简单地写一下:

config.action_mailer.preview_enabled = true
config.action_mailer.preview_path = "#{Rails.root}/lib/mailer_previews"

到我的staging.rb文件,但它给了我method_missing错误。

我做错了什么?有人能帮助我吗?

堆栈追踪:

method_missing': undefined method `preview_enabled=' for ActionMailer::Base:Class (NoMethodError)
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/actionmailer-4.2.0.rc1/lib/action_mailer/railtie.rb:41:in `block (3 levels) in <class:Railtie>'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/actionmailer-4.2.0.rc1/lib/action_mailer/railtie.rb:41:in `each'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/actionmailer-4.2.0.rc1/lib/action_mailer/railtie.rb:41:in `block (2 levels) in <class:Railtie>'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/activesupport-4.2.0.rc1/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/activesupport-4.2.0.rc1/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/activesupport-4.2.0.rc1/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/activesupport-4.2.0.rc1/lib/active_support/lazy_load_hooks.rb:44:in `each'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/activesupport-4.2.0.rc1/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/actionmailer-4.2.0.rc1/lib/action_mailer/base.rb:945:in `<class:Base>'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/actionmailer-4.2.0.rc1/lib/action_mailer/base.rb:417:in `<module:ActionMailer>'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/actionmailer-4.2.0.rc1/lib/action_mailer/base.rb:9:in `<top (required)>'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/actionmailer-4.2.0.rc1/lib/action_mailer/railtie.rb:59:in `block in <class:Railtie>'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/activesupport-4.2.0.rc1/lib/active_support/lazy_load_hooks.rb:36:in `call'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/activesupport-4.2.0.rc1/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/activesupport-4.2.0.rc1/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/activesupport-4.2.0.rc1/lib/active_support/lazy_load_hooks.rb:44:in `each'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/activesupport-4.2.0.rc1/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/railties-4.2.0.rc1/lib/rails/application/finisher.rb:62:in `block in <module:Finisher>'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/railties-4.2.0.rc1/lib/rails/initializable.rb:30:in `instance_exec'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/railties-4.2.0.rc1/lib/rails/initializable.rb:30:in `run'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/railties-4.2.0.rc1/lib/rails/initializable.rb:55:in `block in run_initializers'
from /home/vagrant/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
from /home/vagrant/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
from /home/vagrant/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
from /home/vagrant/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/tsort.rb:347:in `block in each_strongly_connected_component'
from /home/vagrant/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/tsort.rb:345:in `each'
from /home/vagrant/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/tsort.rb:345:in `call'
from /home/vagrant/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/tsort.rb:345:in `each_strongly_connected_component'
from /home/vagrant/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
from /home/vagrant/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/railties-4.2.0.rc1/lib/rails/initializable.rb:54:in `run_initializers'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/railties-4.2.0.rc1/lib/rails/application.rb:352:in `initialize!'
from /home/vagrant/workspace/bankfacil/communicator/config/environment.rb:5:in `<top (required)>'
from /home/vagrant/workspace/bankfacil/communicator/config.ru:3:in `require'
from /home/vagrant/workspace/bankfacil/communicator/config.ru:3:in `block in <main>'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/rack-1.6.0.beta2/lib/rack/builder.rb:55:in `instance_eval'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/rack-1.6.0.beta2/lib/rack/builder.rb:55:in `initialize'
from /home/vagrant/workspace/bankfacil/communicator/config.ru:in `new'
from /home/vagrant/workspace/bankfacil/communicator/config.ru:in `<main>'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/rack-1.6.0.beta2/lib/rack/builder.rb:49:in `eval'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/rack-1.6.0.beta2/lib/rack/builder.rb:49:in `new_from_string'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/rack-1.6.0.beta2/lib/rack/builder.rb:40:in `parse_file'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/rack-1.6.0.beta2/lib/rack/server.rb:299:in `build_app_and_options_from_config'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/rack-1.6.0.beta2/lib/rack/server.rb:208:in `app'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/railties-4.2.0.rc1/lib/rails/commands/server.rb:61:in `app'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/rack-1.6.0.beta2/lib/rack/server.rb:336:in `wrapped_app'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/railties-4.2.0.rc1/lib/rails/commands/server.rb:139:in `log_to_stdout'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/railties-4.2.0.rc1/lib/rails/commands/server.rb:78:in `start'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/railties-4.2.0.rc1/lib/rails/commands/commands_tasks.rb:80:in `block in server'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/railties-4.2.0.rc1/lib/rails/commands/commands_tasks.rb:75:in `tap'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/railties-4.2.0.rc1/lib/rails/commands/commands_tasks.rb:75:in `server'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/railties-4.2.0.rc1/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /home/vagrant/.rvm/gems/ruby-2.1.3/gems/railties-4.2.0.rc1/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'

1 个答案:

答案 0 :(得分:3)

它的工作原理,在staging.rb中,只需添加show_previews而不是preview_enabled,如下所示:

config.consider_all_requests_local = true

# mailer previews
config.action_mailer.show_previews = true
config.action_mailer.preview_path = "#{Rails.root}/lib/mailer_previews"