【问题标题】:mailer preview not working邮件预览不起作用
【发布时间】:2017-12-08 05:50:37
【问题描述】:

我的邮件程序名为 send_invoice_mailer.rb(它在 dev 和 prod 中工作)。

我希望能够使用邮件预览来预览 send_checkout_invoice 功能。

routes.rb:

scope "(:locale)", locale: /#{I18n.available_locales.join("|")}/ do
  #app routes
end

/spec/mailers/previews/send_invoice_preview.rb AND /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,这是在 dev 中与乘客一起完成的。应用已多次从以前的 rails 版本升级。

编辑 2:/rails/mailers 也不起作用。是因为区域设置范围吗?

【问题讨论】:

    标签: ruby-on-rails routing actionmailer


    【解决方案1】:

    可以使用默认为 test/mailers/previews 的 preview_path 选项配置邮件预览目录的位置:

    尝试如下更新操作邮件预览的配置路径:

    config.action_mailer.preview_path = "#{Rails.root}/lib/mailer_previews"
    

    如果测试目录不在生产中,则失败。

    检查此链接,这可能会有所帮助

    https://richonrails.com/articles/action-mailer-previews-in-ruby-on-rails-4-1

    【讨论】:

    • 我还必须添加 config.action_mailer.show_previews = true 才能使其正常工作
    【解决方案2】:

    我在 routes.rb 末尾有几条路由可以捕获所有请求。现在完美运行。

    【讨论】:

      猜你喜欢
      • 2016-11-15
      • 2018-09-01
      • 2015-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-27
      • 1970-01-01
      • 2017-10-31
      相关资源
      最近更新 更多