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

128 views
Skip to first unread message

mike

unread,
May 12, 2012, 8:08:33 PM5/12/12
to rubyonra...@googlegroups.com

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

Greg Akins

unread,
May 12, 2012, 8:43:27 PM5/12/12
to rubyonra...@googlegroups.com
On Sat, May 12, 2012 at 8:08 PM, mike <mike...@gmail.com> wrote:

> 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
>

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

--
Greg Akins
http://twitter.com/akinsgre

Javier Quarite

unread,
May 12, 2012, 10:16:48 PM5/12/12
to rubyonra...@googlegroups.com
On Sat, May 12, 2012 at 7:43 PM, Greg Akins <angr...@gmail.com> wrote:
On Sat, May 12, 2012 at 8:08 PM, mike <mike...@gmail.com> wrote:

> 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 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 :)

Javier Q 

dasibre

unread,
May 13, 2012, 8:04:08 AM5/13/12
to Ruby on Rails: Talk
did you install the bcrypt gem. Make sure its added to your gemfile
then run bundle install.....

mike

unread,
May 13, 2012, 10:31:28 PM5/13/12
to rubyonra...@googlegroups.com
I think I figured out what happened.  I installed bcrypt-ruby and ran bundle install but never restarted the server.  Everything's working now.
Reply all
Reply to author
Forward
0 new messages