I have a user_mailer with a layout.
我有一個帶布局的user_mailer。
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.
對於我的一個動作郵件方法,我希望郵件程序不使用默認布局。但我看不到找到No Layout的設置。
Any ideas?
有任何想法嗎?
38
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:
您還可以追加:only => my_action(或:except)來限制它適用的方法,如下所示:
layout false, :only => 'email_method_no_layout'
(applicable API documentation)
(適用的API文檔)
3
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.
布局方法可以接受方法的名稱;使用該方法確定是否顯示布局並返回該名稱或false。
layout :choose_layout
...
private
def choose_layout
if something
return false
else
return 'application'
end
end
3
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
1
You could also be very sketchy and do this before the mail( ) call at the end of the specific mailer action instead:
您也可以非常粗略,並在特定郵件程序操作結束時調用mail()之前執行此操作:
@_action_has_layout = false
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2011/03/07/72085933e31ad487a7de7bb65a977f51.html。