Project

page_adams

0.0
No commit activity in last 3 years
No release in over 3 years
Automatically paginate your ActiveRecord models.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

~> 5.0
 Project Readme

Gem Version

PageAdams

ActiveRecord model pagination made easy.

Installation

Add this line to your application's Gemfile:

gem 'page_adams'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install page_adams

Usage

Include PageAdams in every model you want to paginate

class Article < ApplicationRecord
  include PageAdams
end

That's it. Now you can call Article.page 5 to get the fifth page of paginated results.

page returns a hash with the following structure:

> Article.page 1
=> {:records=>#<ActiveRecord::Relation [#<Article id: 1>]>, :current_page=>1, :total_pages=>4}

in wich

  • the :records key holds an array of instances (or empty) (ActiveRecord::Relation)
  • the :current_page key holds the current retrieved page (Integer)
  • the :total_pages key holds the total number of instances pages (Integer)

You can also specify the page size per method call

> pagination = Article.page(1, 7)
> pagination[:records].size
=> 7

Configuration

At the moment, only page_size can be configured. Create 'config/initializers/page_adams.rb' and write

PageAdams.setup do |config|
  config.page_size = 7
end

Tests

A basic suite of tests has been included into the gem, using RSpec. Clone the project, enter the folder and run rspec.

License

The gem is available as open source under the terms of the MIT License.