[ACCEPTED]-How do I configure devise to use a custom email layout?-mailer

Accepted answer
Score: 65

Found the answer sitting in the Devise Github 2 wiki,

Reading that helps. ;-)

config.to_prepare do
  Devise::Mailer.layout "simple" # simple.haml or simple.erb
  Devise::Mailer.helper :mailer
end

Here is the 1 reference of the wiki page: How To: Create custom layouts

Score: 36

There is also a parent_mailer option in devise.rb, let's say you 9 are sending emails outside of devise, by 8 default this option is set to ActionMailer::Base, but if you 7 have an ApplicationMailer that already is inheriting from 6 ActionMailer::Base, you could change parent_mailer to this and get all 5 your layouts and configurations out of the box.

In any case is 4 a lot cleaner to use this to keep the rails 3 flow of layouts in your applications if 2 you don't want to change anything in the 1 devise mailer controller.

# devise.rb
config.parent_mailer = 'ApplicationMailer'

# application_mailer.rb
class ApplicationMailer < ActionMailer::Base
    layout 'mailer'
end
Score: 19
# Devise::Mailer inherits from ActionMailer::Base other mail will work fine.

## app/mailers/deviser_mailer.rb

class DeviseMailer < Devise::Mailer
  layout 'email'
  default from: I18n.t("mailer.default.from")
end

## then in config/initializer/devise.rb

# Configure the class responsible to send e-mails.
config.mailer = "DeviseMailer"

Make sure to restart your rails server as 1 you changed an initializer.

More Related questions