我的邮件程序名为send_invoice_mailer.rb(它在开发和产品中工作)。
我希望能够使用邮件预览来预览 send_checkout_invoice 函数。
路线.rb:
scope "(:locale)", locale: /#{I18n.available_locales.join("|")}/ do
#app routes
end
/spec/mailers/previews/send_invoice_preview.rb 和 /test/mailers/previews/send_invoice_preview.rb (不确定哪一个是正确的,所以我符号链接了该文件)
class SendInvoicePreview < ActionMailer::Preview
def send_checkout_invoice
#initializing foo
SendInvoice.send_checkout_invoice(foo)
end
end
当我转到:
/rails/mailers/send_invoice/send_checkout_invoice
时,我被重定向到/fr/rails/mailers/send_invoice/send_checkout_invoice
并出现此错误:
No route matches [GET] "/fr/rails/mailers/send_invoice/send_checkout_invoice"
编辑:rails 是 4.2,这是在开发中与乘客一起完成的。 App已从之前的rails版本多次升级。
编辑2:/rails/mailers 也不起作用。是因为语言环境范围吗?
可以使用 Preview_path 选项配置邮件预览目录的位置,默认为 test/mailers/previews:
尝试更新操作邮件预览的配置路径,如下所示:
config.action_mailer.preview_path = "#{Rails.root}/lib/mailer_previews"
如果测试目录不在生产环境中,则会失败。
检查此链接,这可能会有所帮助
https://richonrails.com/articles/action-mailer-previews-in-ruby-on-rails-4-1
我在routes.rb 末尾有几条路由捕获了所有请求。现在可以完美运行了。