Ruby on Rails - Amazing built-in plugin

Is there an easy way to display the entire nested set when using this plugin? What I would like to do is display an unordered list of root nodes with another unordered list inside each child that also contains children, etc.

Any advice is appreciated.

Thanks.

+5
source share
3 answers

There are several ways to do this. The simplest thing is to just start with the roots and analyze each node and these are the children. The first thing I would do is to do partial for node markup:

_your_model.html.erb

<li>
  <%= your_model.name %>

  <% unless your_model.children.empty? %>
    <ul>
      <%= render your_model.children %>
    </ul>
  <% end %>
</li>

Then edit your view so that the first root nodes are displayed:

<ul>
  <% YourModel.roots.each do |node| %>
    <%= render node %>
  <% end %>
</ul>
+4

: Category.order("lft ASC")

:depth, ! , , : depth.

0

All Articles