I'm using the awesome_nested_set plugin in my Rails project. I'm trying to create nested unordered lists like this, but I'm not having any luck:
<ul>
<li>Test 1</li>
<li>
Test 2
<ul>
<li>Test 2.1</li>
<li>Test 2.2</li>
</ul>
</li>
<li>
Test 3
<ul>
<li>Test 3.1</li>
<li>Test 3.2</li>
<li>Test 3.3</li>
</ul>
</li>
</ul>
Also, I was hoping to do this with one db query. There's similar question here with an accepted answer, but the solution does not work for me.
How to render all records from a nested set into a real html tree
Use a partial to render the children and kick it off with children methods:
in: _tree.html.erb
<% content_tag :li, :id => dom_id(menu) do %>
<span class="handle"><%= menu.title %></span>
<% content_tag :ul do %>
<% for child in menu.children do %>
<%= render :partial => "tree", :locals => {:menu => child }%>
<% end %>
<% end unless menu.leaf? %>
<% end %>
in: show.html.erb
<%= render :partial => "tree", :locals => {:menu => @menu} %>
Replace @menu with your object.