Ruby on Rails NoMethodError только при первой загрузке - PullRequest
0 голосов
/ 17 сентября 2011

При первой загрузке приложения появляется ошибка. Если я немедленно перезагружаю страницу, приложение загружается нормально. Это не имеет большого значения в разработке, но в производстве, похоже, кеширует ошибку. Я пробовал ruby ​​1.9.2-p136, 1.9.2-p180, 1.9.2-p290, но все они, кажется, делают то же самое Ниже приведен вывод из среды РАЗВИТИЯ. Далее идет журнал от nginx, который выдает 502 Bad Gateway, по-видимому, кеширующий 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>'

Есть идеи?

1 Ответ

0 голосов
/ 17 сентября 2011

Если ваше приложение не использует ActiveRecord, вы должны настроить свой проект немного по-другому.

В вашем Gemfile вместо добавления 'rails' просто добавьте эти:

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"

Если выВы не используете Test :: Unit, удалите этот фрагмент из приведенного выше.

...