用户控制器中的Rails错误NoMethodError#显示错误

undefined method 'key?' for nil:NilClass

这是我在阅读M. Hartl的Rails教程时遇到的错误。 此外,保存我的user_controller.rb文件并刷新http://localhost:3000/users/1 ,我收到另一个错误:

 Gem::LoadError in UsersController#show bcrypt-ruby is not part of the bundle. Add it to Gemfile. 

然而,bcrypt-ruby在我的gemfile中,并且在我再次刷新之后,此错误消失了。 它有点奇怪。

这是我的user_controller.rb

 class UsersController < ApplicationController def show @user = User.find(params[:id]) end def new end end 

这是我的show.html.erb

 ,  

非常感谢你们。

有同样的问题:(先尝试第3步)

  1. rails命令行> gem install bcrypt-ruby
  2. rails命令行> bundle install(不确定是否需要)
  3. 重新启动Rails服务器(你可以先尝试一下 – 这可能是唯一需要的步骤)

我遇到了类似的困难。 要解决这个问题,我所要做的就是重新启动rails服务器并且工作正常。

我有同样的问题

重新启动服务器后,它工作正常