Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a different layout in Actionmailer messages?

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
like image 566
Johnny Cash Avatar asked Feb 25 '13 23:02

Johnny Cash


1 Answers

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
like image 65
dgilperez Avatar answered Oct 21 '22 22:10

dgilperez