3
votes

undefined method 'key?' for nil:NilClass

This is the error I am getting while going through M. Hartl's Rails Tutorial. Also, after saving my user_controller.rb file and refreshing http://localhost:3000/users/1, I get another error that is:

Gem::LoadError in UsersController#show

bcrypt-ruby is not part of the bundle. Add it to Gemfile.

bcrypt-ruby is in my gemfile however, and after I refresh again this error is gone. Its just a bit weird.

Here is my user_controller.rb

class UsersController < ApplicationController

  def show
    @user = User.find(params[:id])
  end

  def new
  end
end

and here is my show.html.erb

<%= @user.name %>, <%= @user.email %> 

Thank you all very much.

3

3 Answers

4
votes

Had the same problem: (try step 3 first)

  1. rails command line> gem install bcrypt-ruby
  2. rails command line> bundle install (not sure this was needed)
  3. Restart the Rails Server (you could try this first -this may have been the only step needed)
0
votes

I faced similar difficulties. To solve it, all I had to do was restart the rails server and it worked.

0
votes

I had the same problem

it worked after i restarted the server