SimplePaginator
This is a useful pagination library especially building APIs.
Feature
- Does not issue
count
. - You can set max page.
- You can set number of records per page.
Installation
Add this line to your application's Gemfile:
gem 'simple_paginator'
And then execute:
$ bundle
Usage
Include SimplePaginator into your models like below.
class Post < ActiveRecord::Base
include SimplePaginator
end
You can get paginated records using Post.paged(page)
method.
Default is 25 records / page, maximum page number is 10. You will get 26 (per_page + 1) records when you can get next page.
Post.paged(1) #=> returns 26 records at most.
Post.paged #=> same as above.
Post.paged(11) #=> returns 0 records if page (argument) > max_page.
You can use per_page
, max_page
to change default behavior.
class Post < ActiveRecord::Base
include SimplePaginator
per_page 10
max_page 5
end
You are also be able to change them at .paged
option.
These parameters will override per_page
, max_page
values.
Post.paged(1, per_page: 5, max_page: 10)
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request