I'm currently working on a block application that has article / comment models linked through has_many / belongs_to associations. To create the functionality of nested comments, I use a pedigree. However, I would like to get a full load on all descendants of the comment. Any ideas on how to approach this? I tried to use join and where, but it looks like they produce n + 1 queries. This is how I call the method to display them in the view.
<%= nested_comments_display comments.arrange(:order => :created_at) %>
And here is the nested_comments_display method
def nested_comments_display(comments)
comments.map do |comment, sub_comments|
render(comment) + content_tag(:div,nested_comments_display(sub_comments),
:class => "nested_comment")
end.join.html_safe
end
I also use the gem of dignity, and my comment The controller looks like
class CommentsController < ApplicationController
expose(:article)
expose(:comments, ancestor: :article)
expose(:comment, attributes: :comment_params)
....
end