How to configure mailer on rails 4.2 with preview_enabled = true function

Since rails 4.2 is now released, I would like to add previews of mailings to my project in production. After that, I would just put this code:

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

      

to my staging.rb file but it gives me method_missing error.

What am I doing wrong? Can anyone help me?

Stack trace:

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>'

      

+3


source to share


1 answer


This works, in staging.rb, just add show_previews instead of preview_enabled like:



config.consider_all_requests_local = true

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

      

+3


source







All Articles