Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Rails 4.1 to preview e-mails defined inside a mountable engine

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?

like image 339
andy Avatar asked Sep 05 '14 07:09

andy


2 Answers

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.

like image 159
bmac151 Avatar answered Nov 01 '22 16:11

bmac151


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
like image 24
kobaltz Avatar answered Nov 01 '22 15:11

kobaltz