我成功使用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.
也許問題出在模板中?你是否引用任何具有nil值的實例變量? – zetetic 2010-11-11 19:35:09
我不這麼認爲。我認爲它沒有正確訪問perishable_token。 – bgadoci 2010-11-12 22:33:02