rubyonjets / jets

Ruby on Jets
http://rubyonjets.com
MIT License
2.6k stars 181 forks source link

Mailer Previews Not Working #619

Closed pgib closed 11 months ago

pgib commented 2 years ago

Checklist

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 2 years ago

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 2 years ago

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

tongueroo commented 11 months ago

Went through docs for v5 testing and it worked.

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

So seems fixed.