Currently Post.paginate(:page => 2) returns whole collection (which is confusing), but will_paginate Gem always had the default :per_page setting of 30 (also it validates the parameter to be > 1). I looked at contexts/paging.rb and not sure why it doesn't do something like this:
diff --git a/lib/mongoid/contexts/paging.rb b/lib/mongoid/contexts/paging.rb
index 5bfb844..9f906b1 100644
— a/lib/mongoid/contexts/paging.rb
+++ b/lib/mongoid/contexts/paging.rb
@@ -13,12 +13,8 @@ module Mongoid #:nodoc:
- A collection of documents paginated.
- All previous <tt>limit</tt> and <tt>skip</tt> call will be ignored.
def paginate(pager_options={})
- if pager_options[:per_page]
- options[:limit] = pager_options[:per_page].to_i
- if pager_options[:page]
- options[:skip] = (pager_options[:page].to_i - 1) * pager_options[:per_page].to_i
- end
- end
+ options[:limit] = per_page
+ options[:skip] = (page - 1) * per_page
@collection ||= execute(true)
WillPaginate::Collection.create(page, per_page, count) do |pager|
@@ -43,7 +39,7 @@ module Mongoid #:nodoc:
#
- The Integer number of documents in each page.
def per_page
- (options[:limit] || 20).to_i
+ (options[:limit] || 30).to_i
end
end
end