{"id":25282262,"url":"https://github.com/ppostma/smart_paginate","last_synced_at":"2025-10-27T18:31:17.818Z","repository":{"id":54230194,"uuid":"61298140","full_name":"ppostma/smart_paginate","owner":"ppostma","description":"Simple, smart and clean pagination extension for Active Record and plain Ruby Arrays.","archived":false,"fork":false,"pushed_at":"2024-11-10T13:00:38.000Z","size":77,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-11T07:54:33.833Z","etag":null,"topics":["activerecord","pagination","ruby"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ppostma.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-06-16T14:00:53.000Z","updated_at":"2024-11-10T13:00:42.000Z","dependencies_parsed_at":"2024-11-10T13:32:17.799Z","dependency_job_id":"b69eba69-e33b-4ddf-9eaa-08e34c0326f2","html_url":"https://github.com/ppostma/smart_paginate","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ppostma%2Fsmart_paginate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ppostma%2Fsmart_paginate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ppostma%2Fsmart_paginate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ppostma%2Fsmart_paginate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ppostma","download_url":"https://codeload.github.com/ppostma/smart_paginate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238461528,"owners_count":19476343,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["activerecord","pagination","ruby"],"created_at":"2025-02-12T19:33:53.081Z","updated_at":"2025-10-27T18:31:17.525Z","avatar_url":"https://github.com/ppostma.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SmartPaginate\n\n[![Gem Version](https://badge.fury.io/rb/smart_paginate.svg)](https://badge.fury.io/rb/smart_paginate)\n[![Build Status](https://github.com/ppostma/smart_paginate/actions/workflows/test.yml/badge.svg)](https://github.com/ppostma/smart_paginate/actions)\n[![Code Climate](https://codeclimate.com/github/ppostma/smart_paginate/badges/gpa.svg)](https://codeclimate.com/github/ppostma/smart_paginate)\n\nSimple, smart and clean pagination extension for Active Record and plain Ruby Arrays:\n\n- **Simple:** Easy to use, with a simple interface. It just does pagination, nothing more.\n- **Smart:** Can navigate through the pages without having to do an expensive count query. SmartPaginate will actually fetch one record more than needed and use it to determine if there's a next page.\n- **Clean:** The code is as minimal as possible while still useful. SmartPaginate does not auto include itself or monkey patch any classes.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'smart_paginate'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install smart_paginate\n\n## Usage\n\n### Active Record\n\nTo enable pagination in an Active Record model, include the `SmartPaginate` concern in your class:\n\n```ruby\nclass User \u003c ActiveRecord::Base\n  include SmartPaginate\nend\n```\n\nThen you can use the `paginate` scope to paginate results:\n\n```ruby\nusers = User.order(:name).paginate(page: 1, per_page: 20)\n```\n\nAfter using `paginate`, the following methods will be available to query the next page, number of pages, etc:\n\n```ruby\nusers.next_page?      # true when a next page exists\nusers.next_page       # returns next page number\nusers.previous_page?  # true when a previous page exists\nusers.previous_page   # returns previous page number\nusers.total_entries   # returns total number of entries (!)\nusers.total_pages     # returns total number of pages (!)\n```\n\n**(!) Please note** that the `total_entries` and `total_pages` methods will do a `SELECT COUNT(*)` query to retrieve the total number of entries. This can be very expensive on a table with many records!\n\n### Array\n\nFor paginating Arrays, use the class `SmartPaginate::PaginatingArray` to convert a plain Array to a paginatable Array:\n\n```ruby\narray = (1..100).to_a\narray = SmartPaginate::PaginatingArray(array)\narray.paginate(page: 1, per_page: 20)\n```\n\n### Helpers\n\nBecause SmartPaginate was designed to be as simple and clean as possible, it does not provide any helpers to create pagination links in your views. It is however very easy to write your own, e.g. for Rails:\n\n```ruby\nmodule PaginateHelper\n  def paginate(collection, options = {})\n    content_tag(:div, class: \"pagination\") do\n      if collection.present?\n        concat link_to(\"Previous\", url_for(options.merge(per_page: collection.per_page, page: collection.previous_page)), class: \"previous_page\") if collection.previous_page?\n        concat link_to(\"Next\", url_for(options.merge(per_page: collection.per_page, page: collection.next_page)), class: \"next_page\") if collection.next_page?\n      end\n    end\n  end\nend\n```\n\nWhich you can then use in the view like this:\n\n```ruby\n\u003c%= paginate(@objects, params.permit) %\u003e\n```\n\nMake sure you whitelist the allowed parameters!\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/ppostma/smart_paginate.\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fppostma%2Fsmart_paginate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fppostma%2Fsmart_paginate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fppostma%2Fsmart_paginate/lists"}