We have SomeMailer
set up inside our engine. Upon generation of the mailer, Rails creates an SomeMailerPreview
class, with the comment:
# Preview this email at http://localhost:3000/rails/mailers/some_mailer/test
However, once I run the Dummy
app inside my engine, that URL doesn't resolve.
The engine is mounted on the root path '/':
mount MyEngine::Engine => "/"
I've tried different combinations of the url with the engine name in there, but doesn't resolve.
Is it possible to use the preview feature for a mailer inside an engine?
A little late on this but figured I would answer anyway. You can get your previews recognized by letting rails know where the previews path is. By default, it looks in
"#{Rails.root}/test/mailers"
and so your mailer previews have to be there for the url to resolve correctly. But you can change this by setting the path yourself in the development.rb file of Dummy
config.action_mailer.preview_path = "#{YourEngineRoot}/test/mailers"
And placing your previews in the path given. Your Url should resolve correctly after that.
I have the same issue. Luckily in my case, my engine is directly reliant on the main application. In the main application, I have my mailer previews even though the mailer is within my engine.
class ApplicantMailerPreview < ActionMailer::Preview
# Accessible from http://localhost:3000/rails/mailers/applicant_mailer/applicant_email
def applicant_email
recipient = MyEngine::ApplicantEmail.all.first
applicant = recipient.applicant
job = applicant.job
MyEngine::ApplicantMailer.applicant_email(job.id, applicant.id, recipient.id)
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With