Rails mailer previews not available from spec/mailers/previews

两盒软妹~` 提交于 2019-12-23 06:59:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!