在非开发层上预览邮件 [英] Previewing Mailers on non-development tiers

查看:92
本文介绍了在非开发层上预览邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 spec / mailer / previews 下有几个邮件预览。在开发中,我可以在 / rails / mailers / 下查看所有预览。但是默认情况下,此功能在其他环境中不存在。

I have several mailer previews under spec/mailer/previews. On development I can view all the previews under /rails/mailers/. However by default this functionality does not exist on other environments.

我想在 staging 环境中启用它,然后从此帖子排队。

I wanted to enable it on the staging environment and took a queue from this post here.

以下更改-

# Add the routes manually
if Rails.env.staging?
  get "/rails/mailers" => "rails/mailers#index"
  get "/rails/mailers/*path" => "rails/mailers#preview"
end



config / environments / staging.rb



config/environments/staging.rb

Rails.application.configure do
  # Define the mailer preview path
  config.action_mailer.preview_path = "spec/mailers/previews"

  # Specifically add that path and all files under it to the autoload paths
  config.autoload_paths = Dir["#{config.root}/#{config.action_mailer.preview_path}/**"]
end

class ::Rails::MailersController
  include Rails.application.routes.url_helpers

  # Override the method just for this controller so `MailersController` thinks
  # all requests are local.
  def local_request?
    true
  end
end

但是在分期中,我是m在尝试加载 / rails / mailers 页面时收到以下错误-

However on staging, I'm getting the following error when trying to load the /rails/mailers page -

LoadError (No such file to load -- spec/mailers/previews/admin_mailer_preview):

奇怪的是...该文件肯定存在。当我检查暂存文件的自动加载路径时,该文件肯定在数组/列表中。

The odd thing is... that file definitely exists. And when I check the autoload paths on staging that file is definitely in the Array/list.

对这里可能发生的事情有什么想法,或者我应该如何公开该端点?

Any thoughts on what might be happening here, or how else I should go about exposing that endpoint?

谢谢!

推荐答案

这取决于您正在运行的Rails版本,但是如果您使用的是4.2+版本,请将这些行添加到 staging.rb 应该有帮助:

It depends on what Rails version are you running, but if you are on 4.2+ adding these lines to staging.rb should help:

config.action_mailer.show_previews = true
config.consider_all_requests_local = true

这篇关于在非开发层上预览邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆