加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 在非开发层上预览Mailers

发布时间:2020-12-16 22:54:43 所属栏目:百科 来源:网络整理
导读:我在spec / mailer / previews下有几个邮件预览.在开发中,我可以查看/ rails / mailers /下的所有预览.但是,默认情况下,此功能在其他环境中不存在. 我想在登台环境中启用它并从this post here开始排队. 我做了以下更改 – 配置/ routes.rb中 # Add the route
我在spec / mailer / previews下有几个邮件预览.在开发中,我可以查看/ rails / mailers /下的所有预览.但是,默认情况下,此功能在其他环境中不存在.

我想在登台环境中启用它并从this post here开始排队.

我做了以下更改 –

配置/ routes.rb中

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

配置/环境/ 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

但是在暂存时,我在尝试加载/ rails / mailers页面时遇到以下错误 –

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

奇怪的是……那个文件肯定存在.当我检查分段上的自动加载路径时,该文件肯定在数组/列表中.

有关这里可能发生的事情的任何想法,或者我应该如何揭露该端点?

谢谢!

解决方法

这取决于你运行的Rails版本,但如果你在4.2上将这些行添加到staging.rb应该有帮助:
config.action_mailer.show_previews = true
config.consider_all_requests_local = true

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读