Module: Stipa::Model::Pagination::ClassMethods
- Defined in:
- lib/stipa/model/pagination.rb
Instance Method Summary collapse
Instance Method Details
#paginate(page: 1, per_page: 20) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/stipa/model/pagination.rb', line 9 def paginate(page: 1, per_page: 20) page = [page.to_i, 1].max per_page = [per_page.to_i, 1].max total = count records = limit(per_page).offset((page - 1) * per_page).all total_pages = (total.to_f / per_page).ceil { records: records, page: page, per_page: per_page, total: total, total_pages: total_pages, } end |