我有一个Rails应用程序,它使用AngularJS显示和异步更新对象列表(配置为AngularJS资源)。服务器端是否有一种简单的方法对该表进行分页?
答案 0 :(得分:0)
will_paginate gem提供了一种在Rails控制器和模型中对查询进行分页的方法。来自github自述文件:
## perform a paginated query:
@posts = Post.paginate(:page => params[:page])
# or, use an explicit "per page" limit:
Post.paginate(:page => params[:page], :per_page => 30)
## render page links in the view:
<%= will_paginate @posts %>
您可以自定义默认页面内容:
# for the Post model
class Post
self.per_page = 10
end
# set per_page globally
WillPaginate.per_page = 10
使用Active Record 3,您可以执行以下操作:
# paginate in Active Record now returns a Relation
Post.where(:published => true).paginate(:page => params[:page]).order('id DESC')
# the new, shorter page() method
Post.page(params[:page]).order('created_at DESC')
答案 1 :(得分:0)
尝试使用#ngTasty进行分页服务器端 git:https://github.com/zizzamia/ng-tasty docs:http://zizzamia.com/ng-tasty/directive/table-server-side