Max Fred

Joined

130 Experience
0 Lessons Completed
0 Questions Solved

Activity

That makes so much sense, it's just odd that I'm following along verbatim and getting different behavior than what shows in the tutorial when demoing the same code.

I also realized that my comments in general were showing up out of order with the newest ones showing at the top, despite having identitical code to the episode. You might consider a similar fix to show expected order in the view:

show.html.erb

      <%= render @object.comments.where(parent_id: nil).order(created_at: :asc), max_nesting: 5 %>

Cheers and thanks for this wonderful resource!

Posted in How long does it take for comments to post?

I went ahead and created a new thread. Thanks for taking a closer look.

I am trying to implement nested comments with max_nested comments as described in this episode:

https://gorails.com/episodes/nested-comment-threads-in-rails-part-2?autoplay=1

I'm at approximately the 9 minute mark where nested comments after they reach the max are supposed to fall under the last comment listed. I'm expecting them to be in the order posted, but they are reversed with the most recent showing first instead of at the bottom.

Example:

Comments example

This is the code I currently have in _comments.html.erb

<% nesting = local_assigns.fetch(:nesting, 1) %>
<% max_nesting = local_assigns[:max_nesting] %>
<div class='border-left border-bottom border-top p-4 mb-4'>
  <%= comment.user.name %> posted
  <%= simple_format comment.body %>

  <div data-controller='reply'>
    <small>
      <%= link_to "Reply", "#", data: { action: "click->reply#toggle" } %>
      <%= link_to "Delete", [comment.commentable, comment], method: :delete, data: { confirm: "Are you sure you want to delete this comment?" } if comment.user == current_user %>
    </small>
    <%= render partial: 'comments/form', locals: {
      commentable: comment.commentable,
      parent_id: (nesting < max_nesting ? comment.id : comment.parent_id),
      class: 'mt-4 d-none',
      target: 'reply.form'
    } %>
  </div>

  <%= render comment.comments, nesting: nesting + 1, max_nesting: local_assigns[:max_nesting] %>
</div>

_form.html.erb

<%= form_with model: [commentable, Comment.new], html: { class: local_assigns[:class], data: { target: local_assigns[:target] } } do |form| %>
  <div class='form-group'>
    <%= form.text_area :body, placeholder: "Add a comment", class: 'form-control' %>
  </div>

  <div class='form-group'>
    <%= form.hidden_field :parent_id, value: local_assigns[:parent_id] %>
    <%= form.submit class: 'btn btn-primary' %>
  </div>
<% end %>

Posted in How long does it take for comments to post?

I'll go ahead and post the question here in the community and link to the episode I'm having issues with.

Posted in How long does it take for comments to post?

I posted a comment on an episode, but it didn't show, so I followed it up with a simple "test" which also didn't post/register. Is there a comment filter or do comments need approval before they're posted?

Thanks.

logo Created with Sketch.

Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

© 2020 GoRails, LLC. All rights reserved.