У меня официально нет идей: P Я начал думать, что это может быть проблемой с рельсами, но в большинстве случаев, когда я думаю, что я тот, кто совершает ошибку :) Я задавал этот вопрос (по-другому, хотя) 2 раза в StackOverflow, и я не получил правильный ответ. Поэтому я пробую новый подход.
Есть эта строка:
DiscoveredLocation.find_all_by_user_id(user.id, :include => [:boss_kills])
getLocationNextBosses только выполнил вышеуказанную строку.
Что может создать это сообщение об ошибке? Кажется, это часть реализации rails внутри find. Как вы думаете ? (кстати, user.id, безусловно, правильный).
NoMethodError in BossesController#index
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.each
RAILS_ROOT: /Users/hthought/rails/bbg
Application Trace | Framework Trace | Full Trace
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:125:in `add_preloaded_records_to_collection'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:243:in `preload_has_many_association'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:241:in `each'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:241:in `preload_has_many_association'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:120:in `send'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:120:in `preload_one_association'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/ordered_hash.rb:97:in `each'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/ordered_hash.rb:97:in `each'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:114:in `preload_one_association'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:91:in `preload_associations'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:90:in `preload_associations'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:90:in `each'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:90:in `preload_associations'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:1550:in `find_every'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:615:in `find'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:1900:in `find_all_by_user_id'
/Users/hthought/rails/bbg/app/models/boss_kill.rb:12:in `getLocationNextBosses'
/Users/hthought/rails/bbg/app/controllers/bosses_controller.rb:8:in `index'
development.log также показывает:
[4;35;1mBossKill Load (0.3ms)[0m [0mSELECT `boss_kills`.* FROM `boss_kills` WHERE (`boss_kills`.monster_id IN (695794181,732497461)) [0m
[4;36;1mBossKill Columns (11.9ms)[0m [0;1mSHOW FIELDS FROM `boss_kills`[0m
NoMethodError (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.each):
app/models/boss_kill.rb:12:in `getLocationNextBosses'
app/controllers/bosses_controller.rb:8:in `index'
/opt/local/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/opt/local/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/opt/local/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/opt/local/lib/ruby/1.8/webrick/server.rb:162:in `start'
/opt/local/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/opt/local/lib/ruby/1.8/webrick/server.rb:95:in `start'
/opt/local/lib/ruby/1.8/webrick/server.rb:92:in `each'
/opt/local/lib/ruby/1.8/webrick/server.rb:92:in `start'
/opt/local/lib/ruby/1.8/webrick/server.rb:23:in `start'
/opt/local/lib/ruby/1.8/webrick/server.rb:82:in `start'
Rendered rescues/_trace (114.2ms)
Rendered rescues/_request_and_response (0.8ms)
Rendering rescues/layout (internal_server_error)