undefined method `key?' for nil:NilClass,bcrypt-ruby,has_secure_password

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

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

Please post the bcrypt-ruby error you're seeing and the full trace from the 'undefined Method' error

I got (still gettin) that error with device. I’m changing a rails app from 2.3 to 3.2 and it seems that devise uses another type of encryption (I’m not sure I discovered 2 days ago). The only way I log in is using the console:

User.find(1).update_attributes(:password=>“newpassword”,:password_confirmation=>“newpassword”)

and after that I can log in without any trouble but I have to take a look at this error.

Maybe it helps you :slight_smile:

Javier Q

did you install the bcrypt gem. Make sure its added to your gemfile then run 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.