Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails mailer previews not available from spec/mailers/previews

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?

like image 210
chell Avatar asked Aug 29 '16 10:08

chell


3 Answers

Use

config.action_mailer.preview_path = "#{Rails.root}/spec/mailers/previews"

in config/environments/development.rb to define the path where previews are located.

like image 198
ollpu Avatar answered Nov 07 '22 20:11

ollpu


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

like image 35
Flavio Wuensche Avatar answered Nov 07 '22 20:11

Flavio Wuensche


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

like image 2
stevec Avatar answered Nov 07 '22 21:11

stevec