views:

130

answers:

1

How do I reuse the same action mailer template for multiple mailer "actions"?

In ActionController, you can do

...
render :action => 'another_action'

I'd imagine the same thing can be done in ActionMailer, but I couldn't seem to find the right method. If it's relevant, I'm on Rails 2.3.2.

Thanks!

A: 

You're looking for render_message, there is a good example in the API Docs Multipart Message section - pasted below.

  class ApplicationMailer < ActionMailer::Base
    def signup_notification(recipient)
    recipients      recipient.email_address_with_name
    subject         "New account information"
    from            "[email protected]"
    content_type    "multipart/alternative"

  part :content_type => "text/html",
    :body => render_message("signup-as-html", :account => recipient)

  part "text/plain" do |p|
    p.body = render_message("signup-as-plain", :account => recipient)
    p.transfer_encoding = "base64"
  end
end

end

Mike Buckbee