我有一个评论模型,在微博下发布的帖子都是分页的,都显示在同一页面上。
我已经完成了http://railscasts.com/episodes/174-pagination-with-ajax?view=asciicast的所有工作,但一切都应该有效,但问题是微博和公用事业都是分页的,两者都在同一页面上。
这两个分页的链接都会变为href="/users/2?page=2"
而不是href="/users/2/micropost?page=2"
或href="/users/2/comment?page=2"
。我不确定如何解决这个问题。这是我的一些代码。所有建议都非常感谢!
Micropost呈现HTML
<table class="microposts">
<% if microposts.any? %>
<%= render microposts %>
<%= will_paginate microposts, :page_links => false %>
<% else %>
<div class="EmptyContainer"><span class='Empty'>Add a thread!</span></div>
<% end %>
</table>
评论部分HTML
<div id='CommentContainer-<%= micropost.id%>' class='CommentContainer Condensed2'>
<div class='Comment'>
<%= render :partial => "comments/form", :locals => { :micropost => micropost } %>
</div>
<div id='comments'>
<% comments = micropost.comments.paginate(:per_page => 5, :page => params[:page]) %>
<%= render comments %>
<%= will_paginate comments, :class =>"pagination" %>
</div>
</div>
显示页面的用户控制器
def show
@user = User.find(params[:id])
@comment = Comment.find(params[:id])
@micropost = Micropost.new
@comment = Comment.new
@comment = @micropost.comments.build(params[:comment])
@comments = @micropost.comments.paginate(:page => params[:page], :per_page => 5)
@microposts = @user.microposts.order('created_at DESC').paginate(:per_page => 10, :page => params[:page])
respond_to do |format|
format.html
format.js
end
end
答案 0 :(得分:0)
将两者分开,你应该去这里
http://blog.devinterface.com/2011/08/tips-multiple-pagination-with-will_paginate/
你可以传递单独的参数,这样即使两者都在同一页面上,也只有一个会分页