【发布时间】:2010-12-27 03:33:18
【问题描述】:
我一直在努力解决这个问题,但我真的不知道发生了什么。我有一小段代码:
DiscoveredLocation.find_by_user_id(user.id, :include => [:boss_kills])
模型是:
DiscoveredLocation(id, user_id, boss_location_id)
BossKill(user_id, monster_id)
和关联:
Monster belongs_to :boss_location
Monster has_many :boss_kills
BossKill belongs_to :user
BossKill belongs_to :monster
DiscoveredLocation belongs_to :user
DiscoveredLocation belongs_to :boss_location
DiscoveredLocation has_many :monsters, :through => :boss_location
DiscoveredLocation has_many :boss_kills, :through => :monsters
当我执行 find_by 时出现此错误:
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
如果我将包含选项更改为任何其他模型,例如 :monster,它会很好用。我几乎被这个问题所拥有:P。也许有人可以帮助我? :)
【问题讨论】:
标签: ruby-on-rails