【发布时间】:2016-08-28 03:35:49
【问题描述】:
我在spec/mailer/previews 下有几个邮件预览。在development 我可以查看/rails/mailers/ 下的所有预览。但是默认情况下,此功能在其他环境中不存在。
我想在staging 环境中启用它,并从this post here 获取队列。
我做了以下更改 -
config/routes.rb
# 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
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):
奇怪的是……那个文件确实存在。当我在暂存时检查自动加载路径时,该文件肯定在数组/列表中。
对这里可能发生的事情有什么想法,或者我应该如何公开那个端点?
谢谢!
【问题讨论】:
-
你试过
config.action_mailer.preview_path = "#{Rails.root}/spec/mailers/previews" -
做到了!这么愚蠢的事情-谢谢:)
标签: ruby-on-rails actionmailer railtie