新的rails 4.1邮件程序预览操作未找到错误

hel*_*ion 23 actionmailer ruby-on-rails-4

Rails有607个未解决的问题......所以,我不是先把这个漏洞堵住,而是先尝试一下.我已升级到4.1并正在实施rails mailer预览.我尝试升级现有的邮件程序并添加测试/邮件程序/预览目录.当出现以下错误时,我尝试生成一个新的邮件程序.同样的错误.

 class NotifierPreview < ActionMailer::Preview
    def welcome
      Notifier.welcome(User.first)
    end
  end
Run Code Online (Sandbox Code Playgroud)

导致此错误:

 The action 'notifier' could not be found for Rails::MailersController
Run Code Online (Sandbox Code Playgroud)

我试过搜索谷歌,文档,堆栈溢出,但没有任何躲避这个错误.

有人遇到这个或有任何想法吗?

Cal*_*vin 64

默认预览路径是,/test/mailers/previews但rspec将覆盖它/spec/mailers/previews

您可以将路径设置为您喜欢的任何内容:

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

  • 我的英雄!邮件程序预览突然停止工作 - 只是得到一个空白/白页而不是索引.没有意识到rspec与我的邮件路径搞砸了. (9认同)

max*_*s ツ 7

这是因为你使用UserMailerNotifierPreview.将NotifierPreview更改为UserMailerPreview,它将开始工作.检查示例实现https://github.com/RichIsOnRails/ActionMailerPreviewsExample和教程.

干杯!!


Sam*_*uel 5

如果您正在使用rspec,请确保rspec-rails在开发环境中加载gem,否则Rails将在/ test文件夹下查找预览,而不是/ spec.