ruby-on-railsone-to-manyacts-as-tree

Acts_as_tree - one-to-Many: Show Records associated with children on parent page


I have a relatively simple one-to-many relationship and use acts_as_tree to get it organized in the view. It kinda looks like this:

Root

  |_Product 1
  |_Product 2
  |_Category 1.1

        |_Product 3
        |_Product 4
        |_Category 1.1.1

               |_Product 5

The way I set it up is that I list products in the 'show' action of the category. However I can't seem too figure out how to show: Product 1-5 in the 'show' for Category 1, Product 3-5 in Category 1.1 and so on ...

Does anyone have a hint, from where I can pick it up?

Thanks! Val


Solution

  • You may also have a look at the recent ancestry gem designed for high performance when one needs to get all the descendants in one SQL query.