Reputation: 43
s=Food.find("pizza") returns information as <
<#Food:0xcee080c @attributes={"a=>"5"},"food_groups"=>[#Food::FoodGroup:0xcee0028 @attributes = {"gname="pizzatype"}]
category is an instance method available in FoodGroup. When i access the following in rails console as s.food_groups.category
NoMethodError: undefined method `category' for Food::FoodGroup:0xcee080c
Why did Rails add the dependent class at the front. How can I access the FoodGroup category method?
Upvotes: 1
Views: 47
Reputation: 3462
Here s.food_groups returns a array.
So you have to call like s.food_groups.first.category
Upvotes: 1