In Ruby on Rails I have School which has many children. Children which has many activities. And Activity which has one activity_types. I need help nesting includes. In my Children Controller. I have this... which works.
s = School.find(params[:school_id])
@school = s
@children = s.children.includes(:activities).all
But I want to also get the :activity_type from the activities from the children. I tried this
s = School.find(params[:school_id])
@school = s
@children = s.children.includes(:activities => :activity_types).all
But that did not work
Ruby on Rails is a web application framework written in Ruby that offers developers an opinionated approach to application development. Working with Rails gives developers: Conventions for handling things like routing, stateful data, and asset management.
Adding related models means establishing meaningful relationships between them, which then affect how information gets relayed through your application’s controllers, and how it is captured and presented back to users through views. In this tutorial, you will build on an existing Rails application that offers users facts about sharks.
The simplest example of Nested Attributes is with a one-to-one association. To add Nested Attributes support to the product model all you need to do is add the following line: What does this do, exactly?
With your Rails application in place, you can now work on things like styling and developing other front-end components. If you would like to learn more about routing and nested resources, the Rails documentation is a great place to start.
Don't pluralize activity_type
.
s.children.includes(:activities => :activity_type).all
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With