So originally I had a structure like this in my video view:
<% @video.comment_titles.each do |comment_title| %>
<%= comment_title.title %>
<% comment_title.comments.each do |comment| %>
<%= comment.body %>
<% end %>
<% end %>
and this worked fine because when a user added a comment, they picked a comment title that it would be added under, and then all the comments belonging to a title would be added to that title. However, I now want to place the comments into a partial, so I did something like this:
<% @video.comment_titles.each do |comment_title| %>
<%= comment_title.title %>
<% comment_title.comments.each do |comment| %>
<%= render @video.comments %>
<% end %>
<% end %>
and i put all of the comment generation into comments/_comment.html.erb
However, this does not add the comments as I intend them to be added. Comments are added under all comment titles even if they only belong to one comment title.
So my question is how can I move the creation of comments to a partial in the comments directory while keeping my visual structure the same?
That’s because you’re passing all of the video’s comments –
@video.comments– to the partial. Change:to: