我得到“未定义的方法`has_key?'对于nil:NilClass“表示所有错误

时间:2013-04-19 09:02:39

标签: ruby-on-rails ruby-on-rails-3 debugging error-handling

我的Rails版本是3.0.4.rc1和ruby 1.9.3p194

我面临着非常奇怪的问题。

在我的项目中,我得到ERROR NoMethodError: undefined method has_key?' for nil:NilClass in development.log file and浏览器中的内部服务器错误未定义方法has_key?' for nil:NilClass

对于任何错误,如果其无效语句,未定义变量,引发,退出,错误的数据库名称..或其他任何内容,我只收到上述错误消息。令人沮丧的是,我无法知道错误是什么或错误在哪里(行号和文件名)。

如果没有错误,它可以正常工作,但是当出现任何错误(引发,退出或任何其他错误)时,它会显示相同的错误消息。即undefined method has_key?'为零:NilClass`

错误日志:

[2013-04-19 14:41:07] ERROR NoMethodError: undefined method `has_key?' for nil:NilClass
/home/shweta/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.0.4.rc1/lib/active_support/whiny_nil.rb:48:in `method_missing'
/home/shweta/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.2.5/lib/rack/runtime.rb:20:in `call'
/home/shweta/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.0.4.rc1/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
/home/shweta/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.2.5/lib/rack/lock.rb:13:in `block in call'
<internal:prelude>:10:in `synchronize'
/home/shweta/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.2.5/lib/rack/lock.rb:13:in `call'
/home/shweta/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.0.4.rc1/lib/action_dispatch/middleware/static.rb:30:in `call'
/home/shweta/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.0.4.rc1/lib/rails/application.rb:168:in `call'
/home/shweta/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.0.4.rc1/lib/rails/application.rb:77:in `method_missing'
/home/shweta/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.0.4.rc1/lib/rails/rack/log_tailer.rb:14:in `call'
/home/shweta/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.2.5/lib/rack/content_length.rb:13:in `call'
/home/shweta/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.2.5/lib/rack/handler/webrick.rb:52:in `service'
/home/shweta/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/home/shweta/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/home/shweta/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'

this states that such issue arises when there is a syntax error in model,但我的模型文件很好。

请帮忙。

P.S。我在rails console中没有这个问题。

0 个答案:

没有答案