2011-09-16 43 views
0

第一次加载应用程序时,出现错误。如果我立即重新加载页面,应用程序加载正常。这在开发中并不是什么大问题,但在生产中它似乎缓存了错误。我已经尝试过红宝石1.9.2-p136,1.9.2-p180,1.9.2-p290,但他们似乎都这样做。以下是开发环境的输出。更进一步的是来自nginx的日志,它产生了一个502错误的网关,似乎缓存了NoMethodError。Ruby on Rails NoMethodError仅在第一次加载时

$ rails s 
=> Booting WEBrick 
=> Rails 3.0.5 application starting in development on http://0.0.0.0:3000 
=> Call with -d to detach 
=> Ctrl-C to shutdown server 
[2011-09-16 19:13:39] INFO WEBrick 1.3.1 
[2011-09-16 19:13:39] INFO ruby 1.9.2 (2011-07-09) [i686-linux] 
[2011-09-16 19:13:39] INFO WEBrick::HTTPServer#start: pid=2260 port=3000 

Started GET "/" for 127.0.0.1 at 2011-09-16 19:13:42 -0400 

NoMethodError (undefined method `[]' for false:FalseClass): 

Rendered /home/paisley/tool/install/ruby-1.9.2-p290-fts/lib/ruby/gems/1.9.1/gems/actionpack-3.0.5/lib/action_dispatch/middleware/templates/rescues/_trace.erb (0.9ms) 
Rendered /home/paisley/tool/install/ruby-1.9.2-p290-fts/lib/ruby/gems/1.9.1/gems/actionpack-3.0.5/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (6.2ms) 
Rendered /home/paisley/tool/install/ruby-1.9.2-p290-fts/lib/ruby/gems/1.9.1/gems/actionpack-3.0.5/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (11.1ms) 

Started GET "/" for 127.0.0.1 at 2011-09-16 19:13:44 -0400 
    Processing by WelcomeController#index as HTML 
Rendered welcome/index.haml within layouts/application (13.6ms) 
Completed 200 OK in 18ms (Views: 17.5ms) 

Nginx的错误日志如下:

2011/09/16 19:21:29 [error] 15002#0: *30 upstream prematurely closed connection while reading response header from upstream, client: 74.71.201.247, server: redacted.com, request: "GET/HTTP/1.1", upstream: "passenger:unix:/passenger_helper_server:", host: "redacted.com" 
[ pid=19637 thr=74145680 file=utils.rb:176 time=2011-09-16 19:21:29.767 ]: *** Exception NoMethodError in application (undefined method `[]' for false:FalseClass) (process 19637, thread #<Thread:0x8d6bf20>): 
    from /opt/tool/install/ruby-1.9.2-p180-tasks/lib/ruby/gems/1.9.1/gems/activerecord-3.0.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:59:in `establish_connection' 
    from /opt/tool/install/ruby-1.9.2-p180-tasks/lib/ruby/gems/1.9.1/gems/activerecord-3.0.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:55:in `establish_connection' 
    from /opt/tool/install/ruby-1.9.2-p180-tasks/lib/ruby/gems/1.9.1/gems/activerecord-3.0.5/lib/active_record/railtie.rb:59:in `block (2 levels) in <class:Railtie>' 
    from /opt/tool/install/ruby-1.9.2-p180-tasks/lib/ruby/gems/1.9.1/gems/activesupport-3.0.5/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval' 
    from /opt/tool/install/ruby-1.9.2-p180-tasks/lib/ruby/gems/1.9.1/gems/activesupport-3.0.5/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook' 
    from /opt/tool/install/ruby-1.9.2-p180-tasks/lib/ruby/gems/1.9.1/gems/activesupport-3.0.5/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks' 
    from /opt/tool/install/ruby-1.9.2-p180-tasks/lib/ruby/gems/1.9.1/gems/activesupport-3.0.5/lib/active_support/lazy_load_hooks.rb:42:in `each' 
    from /opt/tool/install/ruby-1.9.2-p180-tasks/lib/ruby/gems/1.9.1/gems/activesupport-3.0.5/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks' 
    from /opt/tool/install/ruby-1.9.2-p180-tasks/lib/ruby/gems/1.9.1/gems/activerecord-3.0.5/lib/active_record/base.rb:1900:in `<top (required)>' 
    from /opt/tool/install/ruby-1.9.2-p180-tasks/lib/ruby/gems/1.9.1/gems/passenger-3.0.2/lib/phusion_passenger/utils.rb:397:in `before_handling_requests' 
    from /opt/tool/install/ruby-1.9.2-p180-tasks/lib/ruby/gems/1.9.1/gems/passenger-3.0.2/lib/phusion_passenger/rack/application_spawner.rb:204:in `start_request_handler' 
    from /opt/tool/install/ruby-1.9.2-p180-tasks/lib/ruby/gems/1.9.1/gems/passenger-3.0.2/lib/phusion_passenger/rack/application_spawner.rb:170:in `block in handle_spawn_application' 
    from /opt/tool/install/ruby-1.9.2-p180-tasks/lib/ruby/gems/1.9.1/gems/passenger-3.0.2/lib/phusion_passenger/utils.rb:479:in `safe_fork' 
    from /opt/tool/install/ruby-1.9.2-p180-tasks/lib/ruby/gems/1.9.1/gems/passenger-3.0.2/lib/phusion_passenger/rack/application_spawner.rb:165:in `handle_spawn_application' 
    from /opt/tool/install/ruby-1.9.2-p180-tasks/lib/ruby/gems/1.9.1/gems/passenger-3.0.2/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop' 
    from /opt/tool/install/ruby-1.9.2-p180-tasks/lib/ruby/gems/1.9.1/gems/passenger-3.0.2/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously' 
    from /opt/tool/install/ruby-1.9.2-p180-tasks/lib/ruby/gems/1.9.1/gems/passenger-3.0.2/lib/phusion_passenger/abstract_server.rb:180:in `start' 
    from /opt/tool/install/ruby-1.9.2-p180-tasks/lib/ruby/gems/1.9.1/gems/passenger-3.0.2/lib/phusion_passenger/rack/application_spawner.rb:128:in `start' 
    from /opt/tool/install/ruby-1.9.2-p180-tasks/lib/ruby/gems/1.9.1/gems/passenger-3.0.2/lib/phusion_passenger/spawn_manager.rb:253:in `block (2 levels) in spawn_rack_application' 
    from /opt/tool/install/ruby-1.9.2-p180-tasks/lib/ruby/gems/1.9.1/gems/passenger-3.0.2/lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add' 
    from /opt/tool/install/ruby-1.9.2-p180-tasks/lib/ruby/gems/1.9.1/gems/passenger-3.0.2/lib/phusion_passenger/spawn_manager.rb:246:in `block in spawn_rack_application' 
    from /opt/tool/install/ruby-1.9.2-p180-tasks/lib/ruby/gems/1.9.1/gems/passenger-3.0.2/lib/phusion_passenger/abstract_server_collection.rb:82:in `block in synchronize' 
    from <internal:prelude>:10:in `synchronize' 
    from /opt/tool/install/ruby-1.9.2-p180-tasks/lib/ruby/gems/1.9.1/gems/passenger-3.0.2/lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize' 
    from /opt/tool/install/ruby-1.9.2-p180-tasks/lib/ruby/gems/1.9.1/gems/passenger-3.0.2/lib/phusion_passenger/spawn_manager.rb:244:in `spawn_rack_application' 
    from /opt/tool/install/ruby-1.9.2-p180-tasks/lib/ruby/gems/1.9.1/gems/passenger-3.0.2/lib/phusion_passenger/spawn_manager.rb:137:in `spawn_application' 
    from /opt/tool/install/ruby-1.9.2-p180-tasks/lib/ruby/gems/1.9.1/gems/passenger-3.0.2/lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application' 
    from /opt/tool/install/ruby-1.9.2-p180-tasks/lib/ruby/gems/1.9.1/gems/passenger-3.0.2/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop' 
    from /opt/tool/install/ruby-1.9.2-p180-tasks/lib/ruby/gems/1.9.1/gems/passenger-3.0.2/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously' 
    from /opt/tool/install/ruby-1.9.2-p180-tasks/lib/ruby/gems/1.9.1/gems/passenger-3.0.2/helper-scripts/passenger-spawn-server:99:in `<main>' 

任何想法?

+0

看来这个错误是由于没有使用config/database.yml引起的。一旦我填充了该文件,即使应用程序不使用ActiveRecord或甚至有模型,它也会运行。我会把它留在那里,看看能否帮助任何人弄清楚真正发生了什么。 –

回答

0

如果你的应用程序不使用ActiveRecord,你应该设置你的项目有点不同。

在你的Gemfile,而不是相加 '轨道',只需添加这些:

RAILS_VERSION = '~> 3.0' 

gem 'activesupport',  RAILS_VERSION, :require => 'active_support' 
gem 'actionpack',   RAILS_VERSION, :require => 'action_pack' 
gem 'actionmailer',  RAILS_VERSION, :require => 'action_mailer' 
gem 'railties',   RAILS_VERSION, :require => 'rails' 

这是一个在Rails的一切,除了ActiveRecord的。

现在你还需要修改您的config/application.rb中,所以不是require "rails",它只是做:

require "action_controller/railtie" 
require "action_mailer/railtie" 
require "rails/test_unit/railtie" 

如果你不使用测试::单位,除去从上面摘录railtie 。

+0

有了这个解决方案,你甚至不需要有一个config/database.yml。很好,谢谢。 –