问题
I have project_mailer with layout but I want to use different method if the project_notification method has parameter that unsubscribe_link = true
.
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
回答1:
I asume you already solved your question, I answer to help others:
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
来源:https://stackoverflow.com/questions/15078692/how-to-use-a-different-layout-in-actionmailer-messages