thoughtbot / clearance

Rails authentication with email & password.

Home Page:https://thoughtbot.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Custom mailer layout?

LimeBlast opened this issue · comments

Hi, sorry if this is the wrong place for this question, but I did have a search for the answer without any joy.

Is there a way of setting a custom layout for the forgotten password mailer?

Our app has a app/views/layouts/mailer.text.erb and a app/views/layouts/mailer.html.erb layout file, but they don't appear to be being used when the forgotten password mailer is sent.

I've got the custom view files generated in app/views/clearance_mailer/change_password.html.haml and app/views/clearance_mailer/change_password.text.haml, although I've not made any changes to them.

Thank you.

Thanks for the question @LimeBlast. You should be able to set the mailer's layout in an initializer by calling the .layout method on the mailer.

# config/initializers/clearance.rb
ClearanceMailer.layout("custom_layout")

# app/views/layouts/custom_layout.html.erb
<h1>Custom Header!</h1>
<%= yield %>

I couldn't get this to work in config/initializers/clearance.rb. I put it in config/application.rb like so:

#config/application.rb
config.to_prepare do
  # Optional configuration of view layouts
  # Clearance::PasswordsController.layout "custom_layout"
  ClearanceMailer.layout "custom_mailer_layout"
end