ddnexus /pagy

Agnostic pagination in plain ruby

★ 4,997⑂ 446👁 30⑃ 484● 319▤ 99
RubyMITCreated 2017-12-31ddnexus.github.io/pagy/
Download: Version 43.8.2Version-43.8.2 ↓43.8.22026-11-08
-1
Daily
4,997
stars
446
forks
30
watchers
484
prs
319
issues
99
releases

README

!Coverage 
!Rubocop Status 
 
 
 
 




Pagy the leaping gem!

_Agnostic pagination in plain Ruby_



 [!TIP]
 ⭐ If you like Pagy, please support it with a Star! ⭐






 💚 v3 was already quite snappy...








 ... and now it's more, with less.

- Compatible with all environments and collection types
- It can use OFFSET, COUNTISH, COUNTLESS, KEYSET, KEYNAV, SEARCH, and CALENDAR pagination techniques
- It supports server-side rendering or faster client-side rendering for popular CSS frameworks and APIs
- It autoloads ONLY the methods that you actually use, with almost zero configuration
- It boasts 100% test coverage for Ruby, HTML, and JavaScript end-to-end (E2E)



 💚 Examples

 Pagination code

rb
 Include pagy in your code (usually application_controller.rb)
include Pagy::Method

 Offset-based pagination
@pagy, @records = pagy(:offset, Product.all)

 Keyset-based pagination (fastest technique)
@pagy, @records = pagy(:keyset, Product.order(my_order).all)

 Paginate your collection with one of several paginators
@pagy, @records = pagy(...)


_See all the available paginators_

 JSON:API pagination

ruby
 JSON:API nested query string. E.g.: ?page[number]=2&page[size]=100
@pagy, @records = pagy(:offset, Product.all, jsonapi: true)
@pagy, @records = pagy(:keyset, Product.order(my_order).all, jsonapi: true)
render json: { links: @pagy.urls_hash, data: @records }


 JSON-client pagination

ruby
render json: { pagy: @pagy.data_hash, data: @records }


 Search server pagination

Available paginators: :elasticsearch_rails, :meilisearch, :rails_active_search, :searchkick, :typesense_rails

rb
 Extend your models (e.g. application_record.rb)
extend Pagy::Search

 Paginate with pagy:
search           = Product.pagy_search(params[:q])
@pagy, @response = pagy(:a_search_paginator, search)

 Or get pagy from paginated results:
@results = Product.search(params[:q])
@pagy    = pagy(:a_search_paginator, @results)


 Calendar pagination

Combine time-range and offset pagination.

_(Available time units: year, quarter, month, week, and day)_



ruby
@calendar, @pagy, @records = pagy(:calendar, collection, year: {}, month: {}, offset: {})


ERB



...



 Server side rendering

 series_nav

Default :pagy, :bootstrap and :bulma styles shown.





erb

 




 Client side rendering

rb
 pagy.rb initializer
javascript_dir = Rails.root.join('app/javascript')
Pagy.sync_javascript(javascript_dir, 'pagy.mjs') if Rails.env.development?


 series_nav_js

Faster and responsive

Dynamically fills the container width.




erb

 




 input_nav_js

Fastest! Combines navigation and info in minimum space.



erb

 






 💚 Dev Tools

Integrate pagy with your app's themes interactively (watch demo), and ask specific questions to the Pagy AI __right in your app__! You need only a single line in your page/layout head to get the Pagy Wand and the Pagy AI:

erb





See Dev Tools



 💚 Support and Docs

- Quick Start
- How To (quick recipes)
- Upgrade to 43 (from version 9 or earlier

Discussions

Latest release

Version 43.8.2 43.8.2 2026-11-08
Changes in 43.8.2


- Fix the page placeholder in the Croatian info_tag.no_count (937)
- Require cgi/escape instead of cgi in a_lambda (934)
- Build page URLs 1.5x faster by escaping the query with CGI.escape (933)


CHANGELOG

Upgrading from version 9 or earlier? See the Upgrade Guide.

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON