rubyonjets/jets

Mailer Previews Not Working

Closed this issue · 3 comments

pgib commented

Checklist

  • Upgrade Jets: Are you using the latest version of Jets? This allows Jets to fix issues fast. There's a jets upgrade command that makes this a simple task. There's also an Upgrading Guide: http://rubyonjets.com/docs/upgrading/
  • Reproducibility: Are you reporting a bug others will be able to reproduce and not asking a question. If you're unsure or want to ask a question, do so on https://community.boltops.com
  • Code sample: Have you put together a code sample to reproduce the issue and make it available? Code samples help speed up fixes dramatically. If it's an easily reproducible issue, then code samples are not needed. If you're unsure, please include a code sample.

My Environment

Software Version
Operating System macOS 12.2.1
Jets 3.1.1
Ruby 2.7.2p137

Expected Behaviour

Following the instructions in the documentation should result in the mailer preview showing a preview of the email.

Current Behavior

ArgumentError.

image

Step-by-step reproduction instructions

I created a brand new project and followed the instructions (minus the migration) to turn on mailer previews and create a mailer preview model.

In my real project, I was noticing that the /jets/mailer routes seem to disappear when the Jets::Router::Finder calls reset_routes!. That project was initialized as an api project; however, I did try setting config.mode = 'html' in the environments/development.rb file. It's unclear to me exactly how things are different between api and html mode.

Code Sample

https://github.com/pgib/jets-mailer-preview-example

Solution Suggestion

If there's any guidance to help me trace through how these routes are generated and how the built-in templates are supposed to be served, I'm happy to keep digging. I've ran into a bit of a wall at the moment.

pgib commented

In my real project, I monkey-patched Jets::Router::Finder#reset_routes! to not do anything, and then I manually copied the email.html.erb view into my app as app/views/jets/mailers. I'm at least able to see my individual mailer previews.

config/initializers/finder.rb

# Monkey-patch this to get mailer previews working. For some reason after
# clearing the routes, the internal mailer preview routes are not re-added.
#
# This will likely mean we'll need to restart the server when changing routes.
class Jets::Router
  class Finder
    def reset_routes!
      return
    end
  end
end
pgib commented

(Updated the same project to show the effect of this.)

Went through docs for v5 testing and it worked.

https://docs.rubyonjets.com/docs/email/previews/

So seems fixed.