2011-09-29 30 views

回答

14

http://edgeguides.rubyonrails.org/action_mailer_basics.html

這裏說:

class UserMailer < ActionMailer::Base 
default :from => "[email protected]" 

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 
+2

不,我想從模板*設置主題*而不是在郵件程序代碼中。 – PBJ

+0

抱歉誤會。更新了我的回答 – corroded

+0

@David這個回答在我看來是正確的。你應該考慮標記它。 – aef

10

要從電子郵件視圖本身設置電子郵件的主題行,只需將以下內容放在視圖文件的開頭:

<% message.subject = 'This is my subject line' %> 

這適用於導軌3和4.