如何在Actionmailer邮件中使用其他布局? [英] How to use a different layout in Actionmailer messages?

查看:84
本文介绍了如何在Actionmailer邮件中使用其他布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有带布局的project_mailer,但是如果project_notification方法的参数为 unsubscribe_link = true ,我想使用其他方法。

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


推荐答案

我假设您已经解决了您的问题,我回答是为了帮助其他人:

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

这篇关于如何在Actionmailer邮件中使用其他布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆