Module: Rango::Pagination::DataMapper::Model
- Defined in:
- lib/rango/contrib/pagination/adapters/datamapper.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#paginate(current = 1, per_page = Page.per_page, options = Hash.new) ⇒ Object
the count options are very important Product.count vs.
Instance Attribute Details
#page ⇒ Object
10 11 12 |
# File 'lib/rango/contrib/pagination/adapters/datamapper.rb', line 10 def page @page end |
Instance Method Details
#paginate(current = 1, per_page = Page.per_page, options = Hash.new) ⇒ Object
the count options are very important Product.count vs. Product.count(online: true)
16 17 18 19 20 21 22 |
# File 'lib/rango/contrib/pagination/adapters/datamapper.rb', line 16 def paginate(current = 1, per_page = Page.per_page, = Hash.new) current = current ? current.to_i : 1 # current can be nil or "1" page = Page.new(current: current, count: self.count(), per_page: per_page) offset = page.number(:db) * page.per_page dataset = self.all(.merge!(offset: offset, limit: page.per_page)) return page, dataset end |