Nested in Ruby on Rails 3

In Ruby on Rails, I have a School with a lot of children. Children who have many activities. And an activity that has one activity_types. I need help developing. In my children's controller. I have this ... that works.

s = School.find(params[:school_id]) @school = s @children = s.children.includes(:activities).all 

But I also want to get: activity_type from actions from children. I tried this

 s = School.find(params[:school_id]) @school = s @children = s.children.includes(:activities => :activity_types).all 

But it didn’t work

+6
source share
1 answer

Do not pluralize activity_type .

s.children.includes(:activities => :activity_type).all

+9
source

Source: https://habr.com/ru/post/909349/


All Articles