将评论移至部分内容时遇到的问题
所以最初我在视频视图中有这样的结构:
<% @video.comment_titles.each do |comment_title| %>
<%= comment_title.title %>
<% comment_title.comments.each do |comment| %>
<%= comment.body %>
<% end %>
<% end %>
这工作得很好,因为当用户添加评论时,他们选择了一个评论标题,将其添加到下面,然后属于标题的所有评论都将添加到那个标题。但是,我现在想将评论放入部分中,所以我做了这样的事情:
<% @video.comment_titles.each do |comment_title| %>
<%= comment_title.title %>
<% comment_title.comments.each do |comment| %>
<%= render @video.comments %>
<% end %>
<% end %>
并且我将所有评论生成放入 comments/_comment.html.erb
但是,这不会添加我想要的评论额外。即使评论只属于一个评论标题,评论也会添加到所有评论标题下。
所以我的问题是如何将评论的创建移动到评论目录中的一部分,同时保持视觉结构相同?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是因为您将视频的所有评论 -
@video.comments
- 传递给部分评论。更改:至:
That's because you're passing all of the video's comments -
@video.comments
- to the partial. Change:to:
您的意思是:
?
Do you mean:
?