title: How to create jQuery function for replying nested commens in Rails
body: <p>How to create//change my jQuery function in create.js.erb file for creating nested comments like in the sreenshot. While creation comment using Js from create.js.erb <strong>helper method doesn't call</strong>? How to fix that?</p>
  
  <p><a href="https://i.stack.imgur.com/xccRD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xccRD.png" alt="enter image description here"></a>
  Comments_helper.rb</p>
  
  <pre><code> module CommentsHelper
        def comments_tree_for(comments)
          comments.map do |comment, nested_comments|
            render(comment) +
                (nested_comments.size &gt; 0 ? content_tag(:div, comments_tree_for(nested_comments), class: "replies") : nil)
          end.join.html_safe
        end
      end
  </code></pre>
  
  <p>Index.html.erb</p>
  
  <pre><code>&lt;div class="jumbotron"&gt;
    &lt;div class="container"&gt;
      &lt;h1&gt;Join the discussion&lt;/h1&gt;
      &lt;p&gt;Click the button below to start a new thread:&lt;/p&gt;
      &lt;p&gt;
        &lt;%= link_to 'Add new topic', new_comment_path, class: 'btn btn-primary btn-lg' %&gt;
      &lt;/p&gt;
    &lt;/div&gt;
      &lt;%= comments_tree_for @comments %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>_commnet.html.erb</p>
  
  <pre><code>&lt;div  id="comment-cont_&lt;%= comment.id %&gt;" class="well"&gt;
    &lt;h2&gt;&lt;%= comment.title %&gt;&lt;/h2&gt;
    &lt;p class="text-muted"&gt;&lt;%= comment.root? ? "Started by" : "Replied by" %&gt; &lt;strong&gt;Alex Petrov &lt;/strong&gt; on
      &lt;%= l(comment.created_at, format: '%B, %d %Y %H:%M:%S') %&gt;&lt;/p&gt;
  
  &lt;% from_reply_form ||= nil %&gt;
  &lt;% unless from_reply_form %&gt;
    &lt;% if comment.leaf? %&gt;
      &lt;small class="text-muted"&gt;There are no replies yet - be the first one to reply!&lt;/small&gt;
    &lt;% end %&gt;
  
    &lt;p&gt;&lt;div id="reply-comment_&lt;%= comment.id%&gt;"&gt;&lt;%= link_to 'reply', new_comment_path(comment.id), remote: true %&gt;&lt;/p&gt;&lt;/div&gt;
  &lt;% end %&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>create.js.erb </p>
  
  <pre><code>$('#reply-comment_&lt;%= @comment.parent_id %&gt;').hide();
  $("#comment-cont_&lt;%= @comment.id %&gt;").prepend('&lt;%= j render @comment %&gt;');
  </code></pre>