未定义的方法`key?'对于 nil:NilClass 带有 bcrypt-ruby 和 has_secure_password [英] undefined method `key?' for nil:NilClass with bcrypt-ruby and has_secure_password
问题描述
我正在使用 Rails for Rails 3.1 完成 DHH 的敏捷 Web 开发.在第 14 章中,他们使用 has_secure_password 方法创建了一个用户登录模型/视图/控制器.我的 user.rb 文件如下所示:
I'm going through DHH's Agile Web Development with Rails for Rails 3.1. In chapter 14 they create a Users sign-in model/view/controller using the has_secure_password method. My user.rb file looks like this:
class User < ActiveRecord::Base
attr_accessible :name, :password_digest, :password, :password_confirmation
validates :name, presence: true, uniqueness: true
has_secure_password
end
现在,当我转到 localhost:3000/users/new 时,我首先遇到某种 bcrypt-ruby 错误,然后当我重新加载页面时,我得到一个未定义的方法 `key?'对于 nil:NilClass
now when I go to localhost:3000/users/new I first get some kind of bcrypt-ruby error and then when I reload the page I get a undefined method `key?' for nil:NilClass
我不知道需要做什么,迈克
I don't know what needs to be done, mike
推荐答案
我想我知道发生了什么.我安装了 bcrypt-ruby 并运行了 bundle install 但从未重新启动服务器.现在一切正常.
I think I figured out what happened. I installed bcrypt-ruby and ran bundle install but never restarted the server. Everything's working now.
这篇关于未定义的方法`key?'对于 nil:NilClass 带有 bcrypt-ruby 和 has_secure_password的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!