2012-01-13 534 views
0

我想在用戶填充空白後將信息形成郵件。但我無法將用戶的模型屬性以HTML格式發送到我的郵件地址。Rails 3 ActionMailer模型屬性

class DemandMailer < ActionMailer::Base 
    default from: "[email protected]" 

    def demand_call(demand) 
     mail(:to => "[email protected]" , :subject => "user registered") 
    end 
end 

和demand_call.html.erb就是這樣

the user name is <%= @demand.name %> 

但錯誤是

ActionView::Template::Error (undefined method `name' for nil:NilClass): 

我該怎麼解決呢?

回答

0

你應該定義實例變量裏面方法

class DemandMailer < ActionMailer::Base 
    default from: "[email protected]" 

    def demand_call(demand) 
     @demand = demand 
     mail(:to => "[email protected]" , :subject => "user registered") 
    end 
    end 

:)你的建議是工作不是可以用它裏面查看

the user name is <%= @demand.name %> 
+0

感謝。 – ndrx42 2012-01-13 13:07:38