How to use Rails 4.1 to preview emails defined inside a mounted engine

We have SomeMailerinstalled inside our engine. After generating the mailer, Rails creates a class SomeMailerPreviewwith a comment:

# Preview this email at http://localhost:3000/rails/mailers/some_mailer/test

However, as soon as I run the application Dummyinside my engine, this URL will not be resolved.

The engine is installed on the root path '/':

mount MyEngine::Engine => "/"

I tried different combinations of URLs with the name of the engine there, but don't allow it.

Can I use the preview function for the mail program inside the engine?

+4
source share
2 answers

, , . , , .

"#{Rails.root}/test/mailers"

, URL- . , development.rb Dummy

config.action_mailer.preview_path = "#{YourEngineRoot}/test/mailers"

. URL .

+3

. , . , .

  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
0

All Articles