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>