© 2018 Domizio DemichelisMIT License


This is a Pagy subclass that provides pagination without the need of any :count. That may be especially useful in the following scenarios:

This class is providing support for extras that don’t need the full set of pagination support or need to avoid the :count variable (e.g. the countless extra). You should not need to use it directly because it is required and used internally.


In this class the :count variable is always nil, hence some feature that depends on it can have limited or no support:

Features with limited support

The nav bar links after the current page cannot be fully displayed because a couple if items of the :size array depends on the count, so they have some limitations.

Regardless the actual :size value:

A few examples:

The series method reflects on the above.

:overflow variable

The available values for the :overflow variable are :empty_page and :exception, missing the :last_page (which is not known in case of an exception).

Features without support

The pagy_info and all the *_compact_nav helpers that use the total count are not supported.

How countless pagination works

Instead of basing all the internal calculations on the :count variable (passed with the constructor), this class uses the number of actually retrieved items to deduce the pagination variables.

The retrieved items number is passed in a second step with the finalize method, and it allows to determine if there is a next page, or if the current page is the last page, or if the current request should raise a Pagy::OverflowError exception.

The trick is retrieving items + 1, and using the resulting number to calculate the variables, while eventually removing the extra item from the result. (see the countless.rb extra)


The construction of the final Pagy::Countless object is splitted into 2 steps: the regular initialize method and the finalize method, which will use the retrieved items number to calculate the rest of the pagination integers.


The initial constructor takes the usual hash of variables, calculating only the requested items and the offset, useful to query the page of items.


The actual calculation of all the internal variables for the pagination is calculated using the number of fetched items. The method returns the finalized instance object.