spacemonkey
spacemonkey

Reputation: 20004

How does Rails 3 actionmailer decide which format to use?

In documentation it says, that mailer actions behave in very similar fashion as controller actions. In rails guide, to send mail:

UserMailer.welcome_email(@user).deliver

and welcome_email action looks like this:

def welcome_email(user)
  @user = user
  @url = "http://example.com/login"
  mail(:to => user.email, :subject => "Welcome to My Awesome Site") do |format|
   format.html { render 'another_template' }
   format.text { render 'another_template' }
  end 
end 

what I don't get is, how welcome_email action decides which format to use (html or text)?

Thanks!

Upvotes: 5

Views: 2753

Answers (1)

chrishomer
chrishomer

Reputation: 4920

I believe it will create a multipart email that includes both html and text parts. This will allow text only clients to render it using that part and html based clients to render it properly too.

Rails 3: http://guides.rubyonrails.org/action_mailer_basics.html

Rails 2: http://guides.rubyonrails.org/v2.3.8/action_mailer_basics.html

Upvotes: 4

Related Questions