2010-11-11 108 views
0

我成功使用Authlogic,並試圖添加用戶通過using this tutorial重置密碼的功能。當我提交請求(以#創建行動PasswordResetsController)重置我收到此錯誤密碼:Authlogic Password_Reset TypeError(無法將nil轉換爲字符串)

TypeError (can't convert nil into String): 
    app/models/user.rb:19:in `deliver_password_reset_instructions!' 
    app/controllers/password_resets_controller.rb:12:in `create' 

我已經通過教程幾次,還通過sample app of it here梳理。我似乎無法弄清楚發生了什麼事。任何人對此實現和錯誤有任何經驗/方向?

以下是完整的終端輸出:

Processing PasswordResetsController#create (for 127.0.0.1 at 2010-11-11 11:32:19) [POST] 
    Parameters: {"commit"=>"Reset my password", "authenticity_token"=>"G2dtgfJJktJN7iX1FWPHvG5wjLKkIXEIZvJ72+zfSIk=", "email"=>"[email protected]"} 
    User Load (0.4ms) SELECT * FROM "users" WHERE ("users"."email" = '[email protected]') LIMIT 1 
    User Update (0.3ms) UPDATE "users" SET "updated_at" = '2010-11-11 17:32:19', "perishable_token" = 'uu_LhCF77GCNbzYfHb2v' WHERE "id" = 1 

TypeError (can't convert nil into String): 
    app/models/user.rb:19:in `deliver_password_reset_instructions!' 
    app/controllers/password_resets_controller.rb:12:in `create' 

Rendered rescues/_trace (129.1ms) 
Rendered rescues/_request_and_response (0.3ms) 
Rendering rescues/layout (internal_server_error) 

User.rb

def deliver_password_reset_instructions! 
     reset_perishable_token! 
     Notifier.deliver_password_reset_instructions(self) 
    end 

更新: 我使用的鐵軌2.3.8和1.8.7的紅寶石

更新: Notifier.rb

default_url_options[:host] = "foobar.com" 

def password_reset_instructions(user) 
    subject  "Password Reset Instructions" 
    from   "foobar" 
    recipients user.email 
    sent_on  Time.now 
    body   :edit_password_reset_url => edit_password_reset_url(user.perishable_token) 
end 

更新: 這裏是/views/notifier/password_rest_instruction.erb

A request to reset your password has been made. If you did not make this request, simply ignore this email. If you did make this request just click the link below: 

<%= @edit_password_reset_url %> 

If the above URL does not work try copying and pasting it into your browser. If you continue to have problem please feel free to contact us. 
+0

也許問題出在模板中?你是否引用任何具有nil值的實例變量? – zetetic 2010-11-11 19:35:09

+0

我不這麼認爲。我認爲它沒有正確訪問perishable_token。 – bgadoci 2010-11-12 22:33:02

回答

0

輸出告訴你有在用戶#deliver_password_reset_instructions 19行錯誤!粘貼你的代碼,我將能夠幫助你更多...

+0

剛剛添加該塊 – bgadoci 2010-11-11 17:57:06

+0

不知道...我會嘗試註釋掉一些代碼。第一個'reset_perishable_token!',第二個'Notifier.deliver_password_reset_instructions(self)',第三個從電子郵件中刪除url,等等...... – jordinl 2010-11-11 22:53:11

+0

我覺得它可能不會正確加載perishable_token,因爲reset_perishable_token之後的下一行是那個抱怨說它不能將nil轉換爲字符串的人。我試着評論一切,並沒有解決它。 – bgadoci 2010-11-12 22:28:24

相關問題