如何配置ActionMailer使用的模板?

Kri*_*ris 1 ruby-on-rails

使用ActionMailer时,它在常规路径中使用"视图",但是如何配置正在使用的"视图"(即选择自己的)?

看起来很容易改变正在使用的'布局',但是你在视图中做同样的事情?

JRL*_*JRL 5

在模型中添加模板命令.例如:

class UserMailer < ActionMailer::Base
  def welcome_email(user)
    recipients user.email
    from "Me<me@example.com>"
    subject "Welcome!"
    sent_on Time.now
    body {:user => user, :url => "http://example.com/login"}
    content_type "text/html"
    ## use some_other_template.text.(html|plain).erb instead
    template "some_other_template"
  end
end
Run Code Online (Sandbox Code Playgroud)

或者,您也可以使用默认视图,但在实际视图中指定一个部分,因此可以像任何普通视图一样使用任何您想要的部分.