Install theme from ActionMailer template in Rails 3?

How to set an object from an ActionMailer Rails 3 template?

I would like to keep the subject and body together.

In Rails 2, you can do the following:

<% controller.subject = 'Change of subject' %> 

(from http://www.quirkey.com/blog/2008/08/29/actionmailer-changing-the-subject-in-the-template/ )

+8
email ruby-on-rails actionmailer
source share
2 answers

http://edgeguides.rubyonrails.org/action_mailer_basics.html

it says that:

 class UserMailer < ActionMailer::Base default :from => "notifications@example.com" def welcome_email(user) @user = user @url = "http://example.com/login" mail(:to => user.email, :subject => "Welcome to My Awesome Site") end end 

If you want to access it from a view:

http://apidock.com/rails/ActionMailer/Base

If you need to access an item, from or to recipients in a view, you can do this through the message object:

  You got a new note from <%= message.from %>! <%= truncate(@note.body, 25) %> 

So you can do:

 message.subject 
+14
source share

To set the subject line of an email message directly from the email view, you can simply put the following at the beginning of a file of the form:

 <% message.subject = 'This is my subject line' %> 

This works for rails 3 and 4.

+10
source share

All Articles