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?
Use
config.action_mailer.preview_path = "#{Rails.root}/spec/mailers/previews"
in config/environments/development.rb
to define the path where previews are located.
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
For me, the solution was to move everything inside
myapp/test/mailers/previews/
to
myapp/spec/mailers/previews/
After doing so, the mailer previews were accessible at the usual URL:
http://localhost:3000/rails/mailers
I found this information here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With