Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 742
spacemonkey Avatar asked Nov 05 '10 12:11

spacemonkey


1 Answers

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

like image 178
chrishomer Avatar answered Oct 15 '22 18:10

chrishomer