问题
I would like to be able to preview my emails in the browser.
I am using Rspec and have the following preview setup in spec/mailers/previews:
# Preview all emails at http://localhost:3000/rails/mailers/employee_mailer
class EmployeeMailerPreview < ActionMailer::Preview
def welcome
Notifier.welcome_email(Employee.first)
end
end
When I try to access this I get the following error:
AbstractController::ActionNotFound at /rails/mailers/employee_mailer
Mailer preview 'employee_mailer' not found
However, when I put the code for the preview inside of tests/mailers/previews it works.
How can I configure my Rails app to look for the previews inside of spec/mailers/previews?
回答1:
Use
config.action_mailer.preview_path = "#{Rails.root}/spec/mailers/previews"
in config/development.rb
to define the path where previews are located.
回答2:
Since you're using RSpec, it's expected that you use the spec
folder.
It that's the case, I'd rather move your file to spec/mailers/previews/user_mailer_preview.rb
来源:https://stackoverflow.com/questions/39204047/rails-mailer-previews-not-available-from-spec-mailers-previews