I’m currently using ‘acts_commentable_with_threading’ on my Post model.
I am able to add comments on the show.html.erb page for the posts. What
I’ve been trying to do is add this logic inside of the posts feed for
users. I can’t seem to add the comments form to the _feed_posts.html.erb
partial. Which has a slide-panel for commenting on user posts.
feed\index.html.erb
_feed_posts.html.erb
-
<% if current_user.liked? post %> <%= link_to dislike_post_path(post), class: 'fa fa-star fa-lg unlike_post', style: 'text-decoration: none; color: yellow;', method: :get do %> <%= post.get_likes.size %> <% end %> <% else %> <%= link_to like_post_path(post), class: 'fa fa-star fa-lg like_post', style: 'text-decoration: none; color: #494c4f;', title: 'like', method: :get do %> <%= post.get_likes.size %> <% end %> <% end %>
-
<% if post.user == current_user && user_signed_in? %><%= link_to 'Delete', post, method: :delete, data: {confirm: 'Are you sure?'}, style: 'color: darkred;' %> <% end %>
-
Reply <%= image_tag 'double-arrow-right.png' %>
Comments <%= post.comment_threads.count == 0 ? "0" : post.comment_threads.count %>
//Comments/reply form inside of slider
</div>
//Comments Partial Form {Doesn’t work in view, but has no issues in show
action for post.}
<%= form_for @new_comment do |f| %>
<%= f.hidden_field :commentable_id, value:
@new_comment.commentable_id %>
<%= f.hidden_field :commentable_type, value:
@new_comment.commentable_type %>
<%= f.text_area :body, class: ‘form-control’ %>
<%= submit_tag ‘Post comment’, class: ‘btn btn-primary-outline
btn-sm’ %>
//Comments _reply.html.erb
<% comments.each do |comment| %>
<%= comment.user.username.capitalize %>
<%= link_to(image_tag(comment.user.avatar_url(:thumb), class:
‘round-image-50’), user_path(comment.user)) %> <%= linkify_hashtags
comment.body %> <%= awesome_link ‘fa-times-circle’, comment, method:
:delete, remote: true, data: {disable_with: ‘Deleting Comment’}, style:
‘color: red;’ %>
<div class="comment-nav"><a href="#" class="comment-reply"><i
class=“fa fa-reply”> Reply
<%= form_for @new_comment do |f| %>
<%= f.hidden_field :commentable_id, value:
@new_comment.commentable_id %>
<%= f.hidden_field :commentable_type, value:
@new_comment.commentable_type %>
<%= f.hidden_field :comment_id, value: comment.id %>
<div class="field form-group">
<%= f.text_area :body, class: 'form-control' %>
</div>
<div class="field form-group">
<%= submit_tag 'Post Reply', class: 'btn btn-primary' %>
</div>
<% end %>
</div>
</div>
<%= render partial: 'comments/reply', locals: {comments:
comment.children} %>
<% end %>
These two forms are actually brought together inside of a template
partial.
<%= commentable.comment_threads.count == 0 ? 'No New' : commentable.comment_threads.count %> Comments
<%= render partial: ‘comments/form’, locals: {new_comment: new_comment}
%>
//Renders comment/reply forms inside of one file
<%= render partial: ‘comments/template’, locals: {commentable: @post,
new_comment: @comment} %>
I need a form instance to populate each slider for each post. The
slide-out panel is working to an extent. It doesn’t populate with data
from nth elements. Only the top element on the page is loaded and I
cannot add comments to it. What approach would you take given the code
that I’ve shown you?