私は公式にアイデアがありません:Pこれはレール問題になるかもしれないと思っていますが、私が間違いを犯した人だと思うほとんどの時間:私はこの質問をしましたしかし別の方法で)StackOverflowで2回、私は正しい答えを得られなかった。だから私は新しいアプローチを試みている。find_byの実行中にメソッドエラーが発生しません。これはレールのバグですか?
この行があります:
DiscoveredLocation.find_all_by_user_id(user.id, :include => [:boss_kills])
getLocationNextBossesは上記のみの行を実行します。
このエラーメッセージは何が作成される可能性がありますか?これはfind内のレール実装の一部であるようです。どう思いますか ? (user.idは正しいbtwです)。
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)
getLocationNextBossesメソッドのコードを投稿します。私たちは12行目とそれ以前に何を持っているのか分かりません。 \tデフself.getLocationNextBosses(ユーザー) \t \t DiscoveredLocation.find_by_user_id: –
私はgetLocationNextBossesだけこの行を実行ポストで言う \tエンド – Spyros