只能向服务器发出一次请求而不会失败
我有一个 Rails 应用程序最近表现得很奇怪。如果我启动服务器,我可以执行一个成功的请求,但下一个请求以失败结束(完全相同的请求)。并非所有页面都如此,但对于大多数具有动态内容的页面来说都是如此。发生故障时,我收到此错误:
Processing StartpageController#index (for 127.0.0.1 at 2010-10-05 13:54:16) [GET]
Parameters: {"action"=>"index", "controller"=>"startpage"}
Rendering template within layouts/application
Rendering startpage/index
Complaint Columns (1.9ms) SHOW FIELDS FROM `complaints`
ActionView::TemplateError (You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.include?) on line #9 of app/views/complaints/_recent.html.erb:
6: <% for complaint in @recent %>
7: <li>
8: <div class="span-2">
9: <%= avatar complaint.user %>
10: </div>
11: <div class="span-9 last">
12: <% bubble do %>
app/views/complaints/_recent.html.erb:9
app/views/complaints/_recent.html.erb:6:in `each'
app/views/complaints/_recent.html.erb:6
app/views/startpage/index.html.erb:9
Rendered rescues/_trace (173.4ms)
Rendered rescues/_request_and_response (24.0ms)
Rendering rescues/layout (200)
Tue Oct 05 13:54:17 +0200 2010: Read error: #<NameError: cannot remove Object::ClassMethods>
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-2.3.9/lib/active_support/dependencies.rb:629:in `remove_const'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-2.3.9/lib/active_support/dependencies.rb:629:in `remove_constant'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-2.3.9/lib/active_support/dependencies.rb:629:in `instance_eval'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-2.3.9/lib/active_support/dependencies.rb:629:in `remove_constant'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-2.3.9/lib/active_support/dependencies.rb:476:in `remove_unloadable_constants!'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-2.3.9/lib/active_support/dependencies.rb:476:in `each'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-2.3.9/lib/active_support/dependencies.rb:476:in `remove_unloadable_constants!'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-2.3.9/lib/active_support/dependencies.rb:262:in `clear'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/actionpack-2.3.9/lib/action_controller/dispatcher.rb:64:in `cleanup_application'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/actionpack-2.3.9/lib/action_controller/reloader.rb:17:in `close'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/rack-1.1.0/lib/rack/handler/mongrel.rb:85:in `process'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/mongrel-1.2.0.pre2/lib/mongrel.rb:165:in `process_client'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/mongrel-1.2.0.pre2/lib/mongrel.rb:164:in `each'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/mongrel-1.2.0.pre2/lib/mongrel.rb:164:in `process_client'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/mongrel-1.2.0.pre2/lib/mongrel.rb:291:in `run'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/mongrel-1.2.0.pre2/lib/mongrel.rb:291:in `initialize'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/mongrel-1.2.0.pre2/lib/mongrel.rb:291:in `new'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/mongrel-1.2.0.pre2/lib/mongrel.rb:291:in `run'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/mongrel-1.2.0.pre2/lib/mongrel.rb:274:in `initialize'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/mongrel-1.2.0.pre2/lib/mongrel.rb:274:in `new'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/mongrel-1.2.0.pre2/lib/mongrel.rb:274:in `run'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/rack-1.1.0/lib/rack/handler/mongrel.rb:38:in `run'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/rails-2.3.9/lib/commands/server.rb:111
/Users/rejeep/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/Users/rejeep/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
./script/server:3
include? 方法未在我的代码中的任何位置使用,因此我不知道它来自哪里。
我尝试过许多不同版本的 Ruby、Rails、Mongrel、Passenger、Webrick,...目前我正在使用:
- Ruby: REE 1.8.7
- Rails: 2.3.9
- Mongrel: 1.2.0.pre2
编辑: 我应该说这个问题只发生在开发模式下。
I have a Rails application that lately is behaving very weird. If I start the server, I can do one successful request, but the next one ends with a failure (exactly the same request). This is not true for all pages, but for most with dynamic contents. When the failure occurs, I get this error:
Processing StartpageController#index (for 127.0.0.1 at 2010-10-05 13:54:16) [GET]
Parameters: {"action"=>"index", "controller"=>"startpage"}
Rendering template within layouts/application
Rendering startpage/index
Complaint Columns (1.9ms) SHOW FIELDS FROM `complaints`
ActionView::TemplateError (You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.include?) on line #9 of app/views/complaints/_recent.html.erb:
6: <% for complaint in @recent %>
7: <li>
8: <div class="span-2">
9: <%= avatar complaint.user %>
10: </div>
11: <div class="span-9 last">
12: <% bubble do %>
app/views/complaints/_recent.html.erb:9
app/views/complaints/_recent.html.erb:6:in `each'
app/views/complaints/_recent.html.erb:6
app/views/startpage/index.html.erb:9
Rendered rescues/_trace (173.4ms)
Rendered rescues/_request_and_response (24.0ms)
Rendering rescues/layout (200)
Tue Oct 05 13:54:17 +0200 2010: Read error: #<NameError: cannot remove Object::ClassMethods>
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-2.3.9/lib/active_support/dependencies.rb:629:in `remove_const'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-2.3.9/lib/active_support/dependencies.rb:629:in `remove_constant'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-2.3.9/lib/active_support/dependencies.rb:629:in `instance_eval'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-2.3.9/lib/active_support/dependencies.rb:629:in `remove_constant'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-2.3.9/lib/active_support/dependencies.rb:476:in `remove_unloadable_constants!'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-2.3.9/lib/active_support/dependencies.rb:476:in `each'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-2.3.9/lib/active_support/dependencies.rb:476:in `remove_unloadable_constants!'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-2.3.9/lib/active_support/dependencies.rb:262:in `clear'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/actionpack-2.3.9/lib/action_controller/dispatcher.rb:64:in `cleanup_application'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/actionpack-2.3.9/lib/action_controller/reloader.rb:17:in `close'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/rack-1.1.0/lib/rack/handler/mongrel.rb:85:in `process'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/mongrel-1.2.0.pre2/lib/mongrel.rb:165:in `process_client'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/mongrel-1.2.0.pre2/lib/mongrel.rb:164:in `each'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/mongrel-1.2.0.pre2/lib/mongrel.rb:164:in `process_client'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/mongrel-1.2.0.pre2/lib/mongrel.rb:291:in `run'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/mongrel-1.2.0.pre2/lib/mongrel.rb:291:in `initialize'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/mongrel-1.2.0.pre2/lib/mongrel.rb:291:in `new'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/mongrel-1.2.0.pre2/lib/mongrel.rb:291:in `run'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/mongrel-1.2.0.pre2/lib/mongrel.rb:274:in `initialize'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/mongrel-1.2.0.pre2/lib/mongrel.rb:274:in `new'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/mongrel-1.2.0.pre2/lib/mongrel.rb:274:in `run'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/rack-1.1.0/lib/rack/handler/mongrel.rb:38:in `run'
/Users/rejeep/.rvm/gems/ree-1.8.7-2010.02/gems/rails-2.3.9/lib/commands/server.rb:111
/Users/rejeep/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/Users/rejeep/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
./script/server:3
The include? method is not used anywhere in my code, so I have no idea where it comes from.
I have tried with lots of different versions of Ruby, Rails, Mongrel, Passenger, Webrick, ... Currently I'm using:
- Ruby: REE 1.8.7
- Rails: 2.3.9
- Mongrel: 1.2.0.pre2
EDIT:
I should say that the problem only occurs in development mode.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅此帖子以获取解决方案:工作时在 Rails 中使用 gems,“无法删除 Object::ClassMethods”源自什么?
在我的例子中,出现问题是因为我在 lib 中包含了一个带有公共代码的模块。
See this post for solution: When working with gems in Rails, what does 'cannot remove Object::ClassMethods' stem from?
In my case the problem occurred because I included a module with common code in lib.