module SmartPaginate::ActiveRecordExtension::ClassMethods

Public Instance Methods

paginate(options = {}) click to toggle source
# File lib/smart_paginate/active_record_extension.rb, line 10
def paginate(options = {})
  page = SmartPaginate::Paginate.new(options.fetch(:page), options[:per_page])

  rel = all.extending(RelationMethods)
  # add one more to the limit so we can quickly determine if there are more pages present
  rel = rel.limit(page.per_page + 1).offset(page.offset)
  rel.current_page = page.current_page
  rel.per_page = page.per_page
  rel
end