plataformatec/devise — Issue #1671: Unable to provide different Devise::Mailer layouts based upon resource
Author: mhuggins
Created: 2012-02-20 22:18:56+00:00
State: open

I have two different types of resources, and the layout for each email should different based upon the resource type. I've come across some code that suggests two approaches for specifying the mailer's layout.

**Method 1:** set the layout on the class via the application.rb file.

config.to_prepare do
Devise::Mailer.layout 'email'
end

**Method 2:** create a custom mailer class that inherits from Devise::Mailer, and use that.

class DeviseMailer < Devise::Mailer
layout 'email'
end

config.mailer = "DeviseMailer"

What I'd really like is a solution similar to the following, though I don't know that it would be possible.

config.to_prepare do
Devise::Mailer.layout proc { |resource| resource == :admin ? 'admin_email' : 'user_email' }
end