How to use a different layout in Actionmailer messages?

这一生的挚爱 提交于 2020-04-10 09:30:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!