Show Associated Model As Leaf Nodes?
Closed this issue · 2 comments
perlmunger commented
My model that acts_as_nested set is called Category. It has many Assets. I would like to display my entire hierarchy of categories and their assets in the tree. Is there any way to have the sortable tree display not only children, but also the assets that belong to any given category as leaf nodes?
the-teacher commented
Have no idea how it should looks, but of course you can.
See this part of helper.
https://github.com/the-teacher/the_sortable_tree/blob/master/app/helpers/render_tree_helper.rb#L17
In your case node
is Category
item.
You can implement anything what you need in your custom render helper.
For example
assets_html = ""
node.assets.each do |asset|
assets_html << "<div>#{ asset.image.url }" "#{ asset.title }</div>"
end
"<div>#{ node.title }</div>" + "<div>#{ assets_htm }</div>"
perlmunger commented
Awesome! Thanks again. Love this gem!