2007-02-05
Paginate a collection or an array
关键字: Rails
def paginate_collection(collection, options = {})
default_options = {:per_page => 10, :page => 1}
options = default_options.merge options
pages = Paginator.new self, collection.size, options[:per_page], options[:page]
first = pages.current.offset
last = [first + options[:per_page], collection.size].min
slice = collection[first...last]
return [pages, slice]
end
The above snippet can be invoked using
@pages, @users = paginate_collection User.find_custom_query, :page => @params[:page]
default_options = {:per_page => 10, :page => 1}
options = default_options.merge options
pages = Paginator.new self, collection.size, options[:per_page], options[:page]
first = pages.current.offset
last = [first + options[:per_page], collection.size].min
slice = collection[first...last]
return [pages, slice]
end
The above snippet can be invoked using
@pages, @users = paginate_collection User.find_custom_query, :page => @params[:page]
- 13:31
- 浏览 (2260)
- 评论 (3)
- 分类: Ruby On Rails
- 进入论坛
- 相关推荐
评论
thegiive
2007-02-06
我以前有花點時間寫這個東西
Maybe helpful
http://lightyror.thegiive.net/2006/11/pagination-collection.html
Maybe helpful
http://lightyror.thegiive.net/2006/11/pagination-collection.html
koska
2007-02-05
def list_for_one_category
@category = Category.find(params[:id])
@article_pages, @articles = paginate_collection @category.articles, :per_page => 10
end
@category = Category.find(params[:id])
@article_pages, @articles = paginate_collection @category.articles, :per_page => 10
end
wiwolf
2007-02-05
如果能有一个完整的例子就好了
- 浏览: 10650 次

- 详细资料
搜索本博客
最近加入圈子
最新评论
-
整合File-Column和Rmagic ...
3.安装file-column到app的vendor目录里,直接copy过去就行 ...
-- by xieqibao -
Paginate a collection or ...
我以前有花點時間寫這個東西 Maybe helpful http://ligh ...
-- by thegiive -
Dave 喜欢 Rails 的十大 ...
哈哈,没有XML,这个对我来说也是一个很重要的好处。
-- by ouspec -
Paginate a collection or ...
def list_for_one_category @category = ...
-- by koska -
Paginate a collection or ...
如果能有一个完整的例子就好了
-- by wiwolf






评论排行榜