如何从Rails 3 ActionMailer模板设置主题?
我想把主题和身体放在一起.
在Rails 2中,您可以执行以下操作:
<% controller.subject = 'Change of subject' %>
(自http://www.quirkey.com/blog/2008/08/29/actionmailer-changing-the-subject-in-the-template/起)
解决方法
http://edgeguides.rubyonrails.org/action_mailer_basics.html
它在这里说:
class UserMailer < ActionMailer::Base default :from => "notifications@example.com" def welcome_email(user) @user = user @url = "http://example.com/login" mail(:to => user.email,:subject => "Welcome to My Awesome Site") end end
如果要从视图中访问它:
http://apidock.com/rails/ActionMailer/Base
如果您需要访问主题,来自视图中的收件人,您可以通过邮件对象访问:
You got a new note from <%= message.from %>! <%= truncate(@note.body,25) %>
所以你可以这样做:
message.subject