Module: DataMapper::Is::Pageable::ClassMethods
- Defined in:
- lib/dm-is-pageable/is/class_methods.rb
Instance Method Summary collapse
Instance Method Details
#paginate(opts = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/dm-is-pageable/is/class_methods.rb', line 6 def paginate(opts = {}) page = opts.delete(:page) || 1 per_page = opts.delete(:per_page) || [:per_page] WillPaginate::Collection.create(page, per_page) do |pager| find_opts = [:dm_options].merge(opts) results = all(find_opts.merge(:offset => pager.offset, :limit => pager.per_page)) pager.replace results pager.total_entries = count(find_opts) unless pager.total_entries end end |