Module: Mongoid::Paginate

Defined in:
lib/mongoid/paginate.rb

Instance Method Summary collapse

Instance Method Details

#paginate(options = {}) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/mongoid/paginate.rb', line 3

def paginate(options={})
  per_page = (options[:per_page] || 20).to_i
  page = (options[:page] || 1).to_i
  offset = (page - 1) * per_page

  create_paginatable_collection(skip(offset).limit(per_page).to_a, count, page, per_page)
end