Back to Pagy

Quick Start

docs/guides/quick-start.md

43.5.31.3 KB
Original Source

:icon-rocket:  Quick Start


!!!question Migrating from another pagination gem? Check the Migration Guide first !!!

Steps

Install it...

ruby
gem 'pagy', '~> 43.5' # MINOR version restriction, to avoid breaking changes

Try it...

{{ include "snippets/run-app" app: "demo" }}

Use it...

=== {{ include "snippets/mini-step" step: "•1" }} Include the pagy method where you are going to use it (usually ApplicationController):

ruby
include Pagy::Method

=== {{ include "snippets/mini-step" step: "•2" }} Use it to paginate any collection with any technique:

ruby
@pagy, @records = pagy(:offset, Product.some_scope, **options) # :offset paginator
@pagy, @records = pagy(:keyset, Product.some_scope, **options) # :keyset paginator
@pagy, @records = pagy(...)

Read the Choose Right guide to pick the right paginators for your app

=== {{ include "snippets/mini-step" step: "•3" }} Render navigator tags and other helpers with the @pagy instance methods:

erb
<%# Render navigation bar helpers with various types and styles %>
<%== @pagy.series_nav %>
<%== @pagy.series_nav_js(:bootstrap) %>
<%== @pagy.input_nav_js(:bulma) %>
<%== @pagy.info_tag %>

See all the available @pagy helpers

===