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
Call it from within your action like this:
@pages, @users = paginate_collection User.find_custom_query, :page => @params[:page]
参考资料:
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/61746/viewspace-80650/ ,如需转载,请注明出处,否则将追究法律责任。