Module: Rango::Pagination::DataMapper::Model

Defined in:
lib/rango/contrib/pagination/adapters/datamapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pageObject

Since:

  • 0.2.2



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)

Examples:

Post.paginate(page, order: [:updated_at.desc])

Since:

  • 0.0.2



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, options = Hash.new)
  current = current ? current.to_i : 1 # current can be nil or "1"
  page = Page.new(current: current, count: self.count(options), per_page: per_page)
  offset = page.number(:db) * page.per_page
  dataset = self.all(options.merge!(offset: offset, limit: page.per_page))
  return page, dataset
end