Rails邮件程序预览不适用于规格/邮寄/预览

che*_*ell 13 rspec ruby-on-rails

我希望能够在浏览器中预览我的电子邮件.

我正在使用Rspec并在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
Run Code Online (Sandbox Code Playgroud)

当我尝试访问它时,我收到以下错误:

AbstractController::ActionNotFound at /rails/mailers/employee_mailer
Mailer preview 'employee_mailer' not found
Run Code Online (Sandbox Code Playgroud)

但是,当我将测试/邮件/预览中的预览代码放入其中时,它可以工作.

如何配置我的Rails应用程序以查找spec/mailers/previews中的预览?

oll*_*lpu 19

使用

config.action_mailer.preview_path = "#{Rails.root}/spec/mailers/previews"
Run Code Online (Sandbox Code Playgroud)

config/development.rb以限定预览所在的路径.

  • 我把它放在`config/development.rb`中 (14认同)

Fla*_*che 5

由于您使用的是 RSpec,因此预计您会使用该spec文件夹。

是这样的话,我宁愿将你的文件移至spec/mailers/previews/user_mailer_preview.rb