There are two kinds of nesting you can do: a tree and a nested set.
acts_as_tree parent_id, , , . , .
awesome_nested_set : parent_id, lft rgt. , . , .
, awesome_nested_set . , , . .
: Comment.roots , comment.children.
class ModelController < ApplicationController
def show
@model = Model.find_by_id(params[:id])
@comments = @model.comments.roots
end
end
<ul id="comments">
<% @comments.each do |comment| %>
<%= render :partial => 'comment', :object => comment %>
<% end %>
</ul>
<!-- _comment partial -->
<li class="comment">
<% if comment.children.present? %>
<ul>
<%= render :partial => 'comment', :collection => comment.children %>
</ul>
<% end %>
</li>
, parent_id awesome_nested_set. , , .
. , awesome_nested_set - . ancestry. .