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.
I wanted to enable it on the staging
environment and took a queue from this post here.
I made the following changes -
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
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?
Thanks!
config.action_mailer.preview_path = "#{Rails.root}/spec/mailers/previews"
– Callant