I'd like to add some metadata to the header of my action mailer preview pages. I thought the easiest way would be to override this file somewhere in my project: https://github.com/rails/rails/blob/4-2-stable/railties/lib/rails/templates/rails/mailers/email.html.erb
Seeing as other things can be overridden in the lib/templates folder I thought something similar could work. I've tried the following without luck:
- lib\templates\rails\mailers\email.html.erb
- lib\templates\mailers\email.html.erb
- lib\rails\templates\rails\mailers\email.html.erb
Is it possible to override this file somehow, and if so where?
Ok, so I got this working in the end. Not sure if it's the best solution but it works.
First I copied email.html.erb mentioned in the question and placed it in test/mailers/previews. Then I made the customizations I needed to it and renamed it to email_preview_heading.html.erb.
Next I created a new initializer with an override of the MailersController. I placed the whole preview method from the original code inside, it can be found here: https://github.com/rails/rails/blob/4-2-stable/railties/lib/rails/mailers_controller.rb
The only change I made in the initializer was on row 35 as per below, that lines tells the preview controller which layout to use. The rest of the method was kept as before.
In the layout file I'm showing metadata passed as headers to the email which means I can access them like this: @email.header['description']
Make sure to only pass the headers when in preview mode though.