Find by include nil object error in rails
- by SpyrosP
I've been trying hard to solve this problem but i really don't know what is happening. I have this small piece of code :
DiscoveredLocation.find_by_user_id(user.id, :include => [:boss_kills])
The models are :
DiscoveredLocation(id, user_id, boss_location_id)
BossKill(user_id, monster_id)
and associations :
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
When i executed the find_by i get this error :
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
If i change the include option to any other model, like :monster, it works great. I'm pretty much owned by this problem :P. Maybe somebody can help me ? :)