2013-02-25 20 views
4

我有project_mailer與佈局,但我想使用不同的方法,如果project_notification方法的參數unsubscribe_link = true如何在Actionmailer消息中使用不同的佈局?

layout "project_mail" 

def project_notification(user, projects, unsubsribe_link = false) 
    attachments.inline['logo_252.png'] = File.read(Rails.root + 'public/images/logo_252.png') 
    @user = user 
    @projects = projects 

    mail(:to => user.email, :subject => "New Projects") 
end 
+0

見http://house9.blogspot.com/2012/12/sending-email-with-rails- mailers-random.html您將需要指定郵件區塊中的佈局 – house9 2013-02-26 06:08:20

回答

13

我asume你已經解決了你的問題,我的回答是幫助別人:

layout 'project_mail' 

def project_notification(user, projects, unsubscribe_link = false) 
    attachments.inline['logo_252.png'] = File.read(Rails.root + 'public/images/logo_252.png') 
    @user = user 
    @projects = projects 
    layout_name = unsubscribe_link ? 'other_fancy_layout' : 'project_mail' 

    mail(to: user.email, subject: "New Projects") do |format| 
    format.html { render layout: layout_name } 
    format.text { render layout: layout_name } 
    end 
end 
+1

想與[Devise :: Mailer](http://stackoverflow.com/q/37779661/2832282) – 2016-06-12 22:53:22

+0

@ CyrilDuchon-Doris在這裏相似的答案你是:https://github.com/plataformatec/devise/wiki/How-To:-Create-custom-layouts#application--devise-config – Phil 2017-08-08 11:03:25

相關問題