Reputation: 111080
I have a user_mailer with a layout.
For one of my actionmailer methods I want the mailer to NOT use the default layout. But I can't see to find a setting for No Layout.
Any ideas?
Upvotes: 30
Views: 10795
Reputation: 4201
I did it by using a small function, looking at the action name and return the correct mailer layout to be used:
class TransactionMailer < ApplicationMailer
layout :select_layout
def confirmation_email contact
#code
end
private
def select_layout
if action_name == 'confirmation_email'
false
else
'mailer'
end
end
end
Upvotes: 5
Reputation: 97004
Simply specify in your mailer:
layout false
You can also append :only => my_action
(or :except
) to limit the methods it applies to, like so:
layout false, :only => 'email_method_no_layout'
(applicable API documentation)
Upvotes: 48
Reputation: 715
You could also be very sketchy and do this before the mail( ) call at the end of the specific mailer action instead:
@_action_has_layout = false
Upvotes: 3
Reputation: 26979
The layout method can accept the name of a method; use the method to determine whether to show a layout and return that name or false.
layout :choose_layout
...
private
def choose_layout
if something
return false
else
return 'application'
end
end
Upvotes: 4