GithubHelp home page GithubHelp logo

sebastialonso / page_adams Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 34 KB

ActiveRecord model pagination made easy (no, really).

License: MIT License

Ruby 83.07% JavaScript 2.60% CSS 1.68% HTML 12.66%

page_adams's Introduction

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.

page_adams's People

Contributors

sebastialonso avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.