Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Ruby
  3. activerecord_cursor_paginate

activerecord_cursor_paginate

MITRuby

A Ruby gem providing cursor-based pagination for ActiveRecord relations with support for custom ordering.

GitHubGitHub
158 stars7 forks0 contributors

What is activerecord_cursor_paginate?

ActiveRecordCursorPaginate is a Ruby gem that adds cursor-based pagination to ActiveRecord relations. It solves the problem of unstable pagination in traditional offset/limit approaches by using encoded cursors that uniquely identify records, ensuring consistent results even when data changes between page requests.

Target Audience

Ruby on Rails developers building applications that require efficient, stable pagination through large or frequently updated datasets, such as APIs, dashboards, or data-intensive features.

Value Proposition

Developers choose this gem for its robust handling of dynamic data, support for custom ordering, and performance optimizations through proper indexing, making it a reliable alternative to offset-based pagination in ActiveRecord.

Overview

Cursor-based pagination for ActiveRecord

Use Cases

Best For

  • Building APIs that require stable pagination for mobile or web clients
  • Paginating large datasets where offset/limit performance degrades
  • Implementing infinite scroll features in Rails applications
  • Handling real-time data feeds where records are frequently added or deleted
  • Ordering results by non-ID columns (e.g., name, date) with pagination
  • Creating bidirectional pagination (next/previous) in ActiveRecord queries

Not Ideal For

  • Legacy Rails applications stuck on Ruby <2.7 or Rails <7.0, as the gem only supports newer versions.
  • APIs that must maintain compatibility with clients expecting traditional offset-based pagination (e.g., page numbers).
  • Projects with frequently changing order columns where index maintenance becomes cumbersome and impractical.
  • Simple CRUD applications with small, static datasets where the overhead of cursor pagination and indexing offers minimal benefit.

Pros & Cons

Pros

Stable Dynamic Pagination

Uses encoded cursors to uniquely identify rows, preventing result jumps when records are added or deleted during pagination, as detailed in the 'How does it work?' section.

Flexible Ordering Support

Allows ordering by any column, multiple columns, or custom SQL expressions via Arel.sql, with implicit primary key appending for uniqueness unless disabled.

Bidirectional Page Navigation

Supports forward pagination with 'after' cursors and backward pagination with 'before' cursors, enabling easy iteration over pages in both directions.

Performance with Indexing

Leverages database indexes for ordered columns; the README provides clear examples for adding compound indexes (e.g., on author and id) to optimize query efficiency.

Cons

Mandatory Indexing Overhead

Requires adding specific database indexes for custom order columns to maintain performance, which adds complexity to schema management and migrations.

Limited Backward Compatibility

Only supports Ruby 2.7+ and Rails 7.0+, excluding teams on older versions without a straightforward upgrade path mentioned in the README.

Complex Setup for Advanced Use

Ordering by JOINed columns or custom SQL expressions requires manual SQL qualification and Arel.sql wrapping, increasing the risk of errors and potential performance degradation if not indexed properly.

Frequently Asked Questions

Quick Stats

Stars158
Forks7
Contributors0
Open Issues1
Last commit1 year ago
CreatedSince 2024

Tags

#orm#database#rails#ruby-gem#gem#cursor-pagination#activerecord#pagination#ruby-on-rails#performance

Built With

M
MySQL
R
Rails
R
Ruby
P
PostgreSQL
A
ActiveRecord

Included in

Ruby14.1k
Auto-fetched 1 day ago

Related Projects

will_paginatewill_paginate

Pagination library for Rails and other Ruby applications

Stars5,680
Forks853
Last commit11 months ago
PagyPagy

Agnostic pagination in plain ruby

Stars4,997
Forks446
Last commit4 days ago
order_queryorder_query

Find next / previous Active Record(s) in one query

Stars516
Forks21
Last commit11 months ago
kaminarikaminari

⚡ A Scope & Engine based, clean, powerful, customizable and sophisticated paginator for Ruby webapps

Stars26
Forks3
Last commit1 year ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub