✳  Paginators

The pagy Method

The pagy method provides a common interface to all paginators. Include it where you are going to paginate a collection (usually in ApplicationController):

include Pagy::Method

You can use it to paginate ANY collection, with ANY technique. For example:

@pagy, @records = pagy(:offset, collection, **options)
@pagy, @records = pagy(:keyset, set, **options)
@pagy, @records = pagy(...)
  • :offset, :keyset, etc. are symbols identifying the paginator. They implement the specific pagination.
  • @pagy is the pagination instance. It provides all the instance helper methods to use in your code.
  • @records are the records belonging to the requested page.

Paginators

The paginators are symbolic names of different pagination types/contexts (e.g., :offset, :keyset, countless, etc.). You pass the name to the pagy method and pagy will internally instantiate and handle the appropriate paginator class.

Unordered PostgreSQL collection
Solutions

PostgreSQL collections must be ordered.

Chain something like .order(:id) to your collection. See the PostgreSQL Documentation