Skip to content

Instantly share code, notes, and snippets.

@mettledrum
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mettledrum/1fa7fe3d5404af37076f to your computer and use it in GitHub Desktop.
Save mettledrum/1fa7fe3d5404af37076f to your computer and use it in GitHub Desktop.
_partials for recursively displaying nested comments for a posting
<% @comments.each do |comment_hash| %>
<%= render 'comment_tree', comment_hash: comment_hash %>
<% end %>
<div class="panel panel-default">
<div class="panel-body">
<%= comment_hash[:comment].content %>
<br></br>
<% if children = comment_hash[:children] %>
<% children.each do |child_hash| %>
<%= render 'comment_tree', comment_hash: child_hash %>
<% end %>
<% end %>
</div>
<div class="panel-footer">
by <%= comment_hash[:comment].user.name %> | <%= comment_hash[:comment].created_at.strftime("%d %b. %Y") %>
<span class="pull-right">
<%= link_to 'reply', new_user_posting_comment_path(@user, @posting, parent_id: comment_hash[:comment].id) %>
</span>
</div>
</div>
<div class="panel panel-warning">
<div class="panel-heading">
<%= @posting.title %>
<span class="pull-right">
<%= link_to 'reply', new_user_posting_comment_path(@user, @posting, parent_id: nil) %>
</span>
</div>
<div class="panel-body">
<%= @posting.content %>
<br></br>
<%= render 'comment_forest' %>
</div>
<div class="panel-footer">
by <%= @posting.user.name %>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment