重用动作邮件模板

时间:2009-08-24 22:27:51

标签: ruby-on-rails actionmailer

如何为多个邮件程序“操作”重复使用相同的操作邮件程序模板?

在ActionController中,您可以执行

...
render :action => 'another_action'

我想在ActionMailer中可以做同样的事情,但我似乎找不到合适的方法。如果它是相关的,我在Rails 2.3.2。

谢谢!

1 个答案:

答案 0 :(得分:1)

您正在寻找render_message,API Docs Multipart Message部分有一个很好的示例 - 粘贴在下面。

class ApplicationMailer < ActionMailer::Base
  def signup_notification(recipient)
    recipients      recipient.email_address_with_name
    subject         "New account information"
    from            "system@example.com"
    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