As the title states, I would like to render an ul
-li
-tree based on an awesome_nested_set
model and hit the database only once. I'm using Ruby on Rails 4.1.
My query looks like this:
Page.root.self_and_descendants.where('depth < ?', 2)
What would be an efficient way to do this?
How can I iterate recursively through it, without loosing the where condition? For example, when I ask every Page
instance, if it's a leaf (page_instance.leaf?
), so it wouldn't stop at a depth of 2, but it wouldn't hit the database again until I digging deeper than 2. Can someone help me with the next foot step?
This question is related to a sitemap.