I am using the ancestry gem in rails to nest some comments, and what I wanted was for you to be able to get all comments and then have them all nested. How ever I get the follow
Structure
Your arrange_serializable
seems to be working - I think the problem is with how you're nesting the comments
We found out (took us ages) that if you want to use "nested" categories, you need to use a slash
like this:
So if you're trying to "deep nest", you need to ensure you're including the whole route to the root object. Common logic would suggest "inheriting" from nested objects would also allow them to be nested - not so.
--
Fix
For your id
5
, you should make the ancestry
column this value:
$ rails c
$ comment = Comment.find 5
$ comment.update(ancestry: "3/4")
--
Partial
If you wanted to show a nested array of categories in your view, we use the following code:
#app/views/elements/_category.html.erb
<!-- Categories -->
<ol class="categories">
<% collection.arrange.each do |category, sub_item| %>
<li>
<!-- Category -->
<%= category.title %>
<!-- Children -->
<% if category.has_children? %>
<%= render partial: "category", locals: { collection: category.children } %>
<% end %>
</li>
<% end %>
</ol>
#app/views/application/index.html.erb
<%= render partial: "category", locals: { collection: Category.all } %>