我一直在处理的当前页面是一个用户可以在特定微帖子下创建评论的页面。所有的微柱都显示在同一页上,并且这些微柱被分页。在每个特定的微post下,都有注释,这些注释应该被分页,而我目前遇到的问题是,只有当HTML代码是这样的时候,分页才会发生:
HTML
<div id='comments'>
<%=render @comments %>
<%= will_paginate @comments, :class =>"pagination" %>
</div>
但问题是,只有第一个微帖子的评论才会出现在每一个微帖子上,而不是具体的微帖子评论。所以我想为什么不把代码放成这样:
HTML
<div id='comments'>
<%=render micropost.comments %>
<%= will_paginate @comments, :class =>"pagination" %>
</div>
这基本上把所有具体的评论都设置在了正确的微帖子中,但它没有分页,但显示了分页链接,所以我认为放这个会起作用,但没有,出现了一个错误:
HTML
<div id='comments'>
<%=render micropost.comments %>
<%= will_paginate micropost.comments, :class =>"pagination" %>
</div>
我很困惑,不确定该怎么办,是的,微邮政应该没有@
我很感激任何有帮助的建议!非常感谢。
我的用户#显示
用户控制器
class UsersController < ApplicationController
def show
@user = User.find_by_id(params[:id])
@school = School.find(params[:id])
@micropost = Micropost.new
@comment = Comment.new
@comment = @micropost.comments.build(params[:comment])
@comments = @micropost.comments.paginate(:page => params[:page], :per_page => 10)
@microposts = @user.microposts.paginate(:per_page => 10, :page => params[:page])
end
end
这会起作用,但您需要在视图内部执行赋值这一事实告诉您这可能不是这样做的方法:
<div id='comments'>
<% comments = micropost.comments.paginate(:per_page => 10, :page => params[:page]) %>
<%= render comments %>
<%= will_paginate comments, :class =>"pagination" %>
</div>
一定要意识到;注释都使用相同的页面参数。因此,如果你想查看任何给定微博客的第二页评论,你也会切换到第二页微博客。我会重新考虑在同一页上显示所有这些信息。