guess_paging is a pagination library, and this library work wonderfully when you treat many records in RDB.


Light workload

General pagination libraries calculate records size to display accurate last page number. But sometimes, count query is too heavy workload for database, if you use heavy SQL Query. In the result, page speed slow.

guess_paging calculate and cache records size at the first time. From then on, guess_paging not count records size, and display last page number of suitable size. When user click that last page, once again calculate accurate last page number, and refresh cache. When user visit first page and halfway pages, count query is not called.

So, guess_paging is light workload for database, because it call count query at the first time and last page only.


Add this line to your application's Gemfile:

gem 'guess_paging'

And then execute:

$ bundle

Or install it yourself as:

$ gem install guess_paging


Setup redis

This gem requires redis, so please prepare redis-server and setup redis in initializer.

GuessPaging::RedisClient.setup do |config|
  config.redis_host = ''
  config.redis_port = 6379


class RecordsController < ApplicationController
  def search
    @guess =
      query: Record.where(category_id: params[:category_id].to_i),
      per_page: 10)
      page_params: params[:page]


<%= paging(@guess) %>


  • output pagination view
  <%= paging(@guess) %>
  • current page number
  • last page number of suitable size
  • record number of suitable size.


After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to


Bug reports and pull requests are welcome on GitHub at[USERNAME]/guess_paging. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.


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