【问题标题】:Rails: Ajax/jQuery Issue with PaginationRails:分页的 Ajax/jQuery 问题
【发布时间】:2012-05-09 08:07:06
【问题描述】:

我有一个评论模型,微博下的帖子都是分页的,并且都显示在同一页面上。

我已经从http://railscasts.com/episodes/174-pagination-with-ajax?view=asciicast 完成了所有工作,并且一切都应该正常,但问题是 micropost 和 commet 都是分页的,并且都在同一页面上。

两个分页的链接都变成了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

【问题讨论】:

  • 我希望解决了您的问题 = )

标签: ruby-on-rails ajax ruby-on-rails-3 jquery


【解决方案1】:

要将两者分开,你应该去这里

http://blog.devinterface.com/2011/08/tips-multiple-pagination-with-will_paginate/

你可以传入单独的参数,这样即使两个都在同一个页面上,也只有一个会分页

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-11
    • 1970-01-01
    • 2020-01-26
    • 2015-07-02
    • 2013-12-14
    • 1970-01-01
    • 2020-07-18
    相关资源
    最近更新 更多