Action Pager
Simple, lightweight and easy to customize paginator for collections (Array, ActiveRecord::Relation etc.)
Features
- A simple
pager
object is used for pagination.- It does not pollute the original collection.
- Consumes less memory than other gems (i.e. Kaminari, Will Paginate etc.).
- Easy to customize.
- Paginator view and helper files are generated in your app.
- You can customize for your own purpose.
Installation
Add this line to your application's Gemfile:
gem "actionpager"
And then execute:
$ bundle
Or install it yourself as:
$ gem install actionpager
Use with Rails
$ rails g action_pager:install
It generates two files and you can customize.
app/helpers/action_pager/pagination_helper.rb
app/views/action_pager/_pager.html.erb
By default, it uses Bootstrap 4 pagination for styles. If you need, you can easily customize the generated file.
Usage
Use with a simple array:
collection = (1..128).to_a
pager = ActionPager::Pager.new(collection, page: 3, per: 10)
pager.current_collection # => [21, ..., 30]
Use with an ActiveRecord collection
resources = Book.recent_published
@pager = ActionPager::Pager.new(resources, page: 2, per: 25)
@books = pager.current_collection
To show the pager in your Rails app's view, add code like below:
<%= render_pager @pager %>
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the Actionpager project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.