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!
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With