3

由于现在发布了 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>'
4

1 回答 1

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"
于 2014-12-05T14:15:28.280 回答