sudarson
sudarson

Reputation: 43

Rails 4.0.3 Active resource

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

Answers (1)

Ranjithkumar Ravi
Ranjithkumar Ravi

Reputation: 3462

Here s.food_groups returns a array.
So you have to call like s.food_groups.first.category

Upvotes: 1

Related Questions