【问题标题】:Authlogic Password_Reset TypeError (can't convert nil into String)Authlogic Password_Reset TypeError(无法将 nil 转换为字符串)
【发布时间】:2010-11-11 17:38:38
【问题描述】:

我已成功使用 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)

用户.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.

【问题讨论】:

  • 可能问题出在模板上?您是否引用了任何具有 nil 值的实例变量?
  • 我不这么认为。我认为它没有正确访问 perishable_token。

标签: ruby-on-rails ruby authlogic


【解决方案1】:

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

【讨论】:

  • 不知道...我会尝试注释掉一些代码。第一个 'reset_perishable_token!',第二个 'Notifier.deliver_password_reset_instructions(self)',第三个从电子邮件中删除 url,依此类推...
  • 我觉得它可能没有正确加载 perishable_token,因为 reset_perishable_token 之后的下一行抱怨它无法将 nil 转换为字符串。我尝试将所有内容都注释掉,但 id 没有修复它。
  • 它们似乎工作正常......在控制台中尝试'User.first.reset_perishable_token!'和'Notifier.deliver_password_reset_instructions(User.first)'。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-09
  • 1970-01-01
  • 2013-04-17
  • 1970-01-01
相关资源
最近更新 更多