2011-03-22 77 views
0

我在this Railscast這裏從我的rails應用程序發送郵件。Rails 3:ActionMailer

起初我試圖設置一個像本教程中的郵件攔截器,但我已經放棄了,因爲我總是有一個可愛的can't convert nil into Hash (TypeError)

現在,我離開了攔截器,我想實際發送郵件,但你猜怎麼着 - 我的老朋友又回來了:

can't convert nil into Hash (TypeError) 

app/mailers/user_mailer.rb:20:in `registration' 

這裏的郵件類(行號20是一個與來電來郵):

class UserMailer < ActionMailer::Base 

    def registration(user) 
    @invited = user 

    subject = 'Welcome!' 

    if Rails.env.development? 
     to = '[email protected]' 
     subject = "to #{@invited.email}: #{subject}" 
    else 
     to = @invited.email 
    end 

    logger.info "Sending email to #{to} with subject #{subject}" 

    mail(:from => '[email protected]', :to => to, :subject => subject) 
    end 
end 

日誌顯示:

invite entered for user [email protected] 
Sending email to [email protected] 
Sending email to [email protected] with subject to [email protected]: Welcome! 

而這裏的請求的視圖文件(對準配合文本):

Welcome! 

blablah blah click the following link to activate blah blah <%= activate_user_path(@invited)%> blah blah. 
blah blah this is actually german (but plaintext) encoded in utf-8. 

VielVergnügenbeim Verwenden des Systems!

THX任何幫助

+0

這行是#20在這裏? ) – fl00r 2011-03-22 18:04:42

+0

我認爲你的'user'是'nil' – fl00r 2011-03-22 18:05:34

+0

#20是一個用來調用郵件的(...) – DeX3 2011-03-22 18:19:17

回答

0

做到了,我有一個錯誤的ActionMailer的配置

+0

我被一段時間的同樣的錯誤所困擾。如果你記得,你能提一下你的錯誤嗎? – rohitmishra 2012-12-18 20:58:16