javascript - rails : Render pages of Will_Paginate through Ajax/jQuery

标签 javascript jquery ruby-on-rails ruby ajax

我有一个评论模型,在微帖子模型下发布,它们都在同一页面上。我遇到的问题是,当评论在微帖子下分页时,链接会指向微帖子的第二页而不是评论的第二页,但我不想重定向到第二页,而是希望呈现更多通过分页的评论ajax 但我对如何到达嵌套路由感到困惑。有人对此有什么建议吗?路线部分让我很感兴趣。以下是我的微帖子/评论部分 HTML 的代码。另外,我必须在哪个 Controller 中的哪里插入 respond_to do 部分?谢谢!

微博/评论部分 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>

用户 Controller - 显示的页面

class UsersController < ApplicationController
  def show
    @user = User.find(params[:id])
    @school = School.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])
  end
end

最佳答案

大多数人都遵循经典的railscast:

http://asciicasts.com/episodes/174-pagination-with-ajax

请注意,现在,对于 Rails 3,您只需将其包含在
gem 'will_paginate'
- 当然还有捆绑安装。 - 而不是啰嗦
gem 'mislav-will_paginate', :lib => 'will_paginate', :source => 'http://gems.github.com'

关于javascript - rails : Render pages of Will_Paginate through Ajax/jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9550605/

相关文章:

javascript - 在有和没有更新面板的页面加载中运行功能

javascript - 如何缩短 or 运算符?

javascript - Rails Form_Tag Ajax Format.js ActionController::UnknownFormat

ruby-on-rails - Rails:ActiveRecord::Base.transaction 和 MyClass.transaction 有什么区别?

javascript - 多个文件拖放区域

ruby-on-rails - 如何为 link_to block 传递 html?

javascript - Jquery 无法在 Dreamweaver 中运行。不确定链接是否正确

javascript - 将 init 集合转换为标准对象?

jquery - 创建具有动态值的 json 对象

javascript - 外部网站的html2canvas截图