I have a model User that has multiple referenced "profiles". A user can have several of those profiles, and each of those profiles should induce a specific layout in emails. Let's consider the profiles Admin
and Worker
For example, in my Devise confirmation controller, I need different layouts depending on the profile the user have. For example, if the user has
- Admin profile : render admin template
- Worker profile : render worker template
- Both : render another template (hybrid)
Therefore I cannot set a layout for the Mailer/Controller, but I need to set it inside the controller action. Let's suppose I have a helper layout_for_user() that can return the layout name for a given user. How would I use it ? For example with Devise mailer ?
class MyDeviseMailer < Devise::Mailer
def confirmation_instructions(record, token, options={})
# whange layout based on `layout_for_user(record)`
@token = token
devise_mail(record, :confirmation_instructions, opts)
end
end