Authlogic Password_Reset TypeError(无法将nil转换为String)

时间:2010-11-11 17:38:38

标签: ruby-on-rails ruby authlogic

我正在成功使用Authlogic,我正在尝试为用户添加using this tutorial重设密码的功能。当我提交请求(到PasswordResetsController #create动作)重置密码时,我收到此错误:

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"=>"bgadoci@gmail.com"}
  User Load (0.4ms)   SELECT * FROM "users" WHERE ("users"."email" = 'bgadoci@gmail.com') 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

更新: 我正在使用rails 2.3.8和ruby 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.

1 个答案:

答案 0 :(得分:0)

输出告诉你用户#deliver_password_reset_instructions的第19行有错误!粘贴您的代码,我将能够为您提供更多帮助......