Как создать // изменить мою функцию jQuery в файле create.js.erb для создания вложенных комментариев, как в скриншоте. При создании комментария с использованием Js из create.js.erb вспомогательный метод не вызывает ? Как это исправить?
Comments_helper.rb
module CommentsHelper
def comments_tree_for(comments)
comments.map do |comment, nested_comments|
render(comment) +
(nested_comments.size > 0 ? content_tag(:div, comments_tree_for(nested_comments), class: "replies") : nil)
end.join.html_safe
end
end
index.html.erb
<div class="jumbotron">
<div class="container">
<h1>Join the discussion</h1>
<p>Click the button below to start a new thread:</p>
<p>
<%= link_to 'Add new topic', new_comment_path, class: 'btn btn-primary btn-lg' %>
</p>
</div>
<%= comments_tree_for @comments %>
</div>
_commnet.html.erb
<div id="comment-cont_<%= comment.id %>" class="well">
<h2><%= comment.title %></h2>
<p class="text-muted"><%= comment.root? ? "Started by" : "Replied by" %> <strong>Alex Petrov </strong> on
<%= l(comment.created_at, format: '%B, %d %Y %H:%M:%S') %></p>
<% from_reply_form ||= nil %>
<% unless from_reply_form %>
<% if comment.leaf? %>
<small class="text-muted">There are no replies yet - be the first one to reply!</small>
<% end %>
<p><div id="reply-comment_<%= comment.id%>"><%= link_to 'reply', new_comment_path(comment.id), remote: true %></p></div>
<% end %>
</div>
create.js.erb
$('#reply-comment_<%= @comment.parent_id %>').hide();
$("#comment-cont_<%= @comment.id %>").prepend('<%= j render @comment %>');