order | icon |
---|---|
4 |
rocket-24 |
=== If you want to just try Pagy before using it in your own app, you have a couple of alternatives...
+++ Pagy Application
Ensure to have rack
installed (or gem install rack
)
Download and run any of the following self contained file:
+++ Pagy Console
||| Install the gem
gem install pagy
|||
+++ With Bundler
If you use Bundler, add the gem in the Gemfile, optionally avoiding the next major version with breaking changes ( see RubyGem Specifiers):
||| Gemfile
gem 'pagy', '~> 7.0' # omit patch digit
|||
+++ Without Bundler
If you don't use Bundler, install and require the Pagy gem:
||| Terminal
gem install pagy
|||
||| Ruby file
require 'pagy'
||| +++
+++ With Rails
Download the configuration file linked below and save it into the config/initializers
dir
+++ Without Rails Download the configuration file linked below and require it when your app starts
!file +++
!!! Pagy doesn't load unnecessary code in your app!
Uncomment/edit the pagy.rb
file in order to explicitly require the extras you need and eventually customize the
static Pagy::DEFAULT
variables in the same file.
You can further customize the variables per instance, by explicitly passing any variable to the Pagy*.new
constructor or to
any pagy*
backend/controller method.
!!!
+++ Standard === Include the backend
||| ApplicationController/AnyController
include Pagy::Backend
|||
=== Use the pagy
method
||| Controller action
@pagy, @records = pagy(Product.some_scope)
+++ Search For search backends see: elasticsearch_rails, meilisearch, searchkick, ransack.
+++ Special You may also use the calendar, countless, geared, incremental, auto-incremental, infinite pagination
+++
+++ Server Side !!! success Your pagination is rendered on the server !!!
Include the frontend
||| ApplicationHelper/AnyHelper
include Pagy::Frontend
|||
Use a fast helper ||| Helper
<%# Note the double equals sign "==" which marks the output as trusted and html safe: %>
<%== pagy_nav(@pagy) %>
|||
!!! CSS Frameworks/Styles Available The pagy helpers are available for different frameworks and different styles (static, responsive, compact, etc.) bootstrap, bulma, foundation, materialize, semantic, uikit !!!
+++ Javascript Framework
!!! success Your pagination is rendered by Vue.js, react.js, ... !!!
Require the metadata extra
||| pagy.rb (initializer)
require 'pagy/extras/metadata'
|||
Add the metadata to your JSON response ||| Controller action
render json: { data: @records, pagy: pagy_metadata(@pagy, ...) }
|||
+++ API Service
!!! success Your API is consumed by some client !!!
Require the headers extra
||| pagy.rb (initializer)
require 'pagy/extras/headers'
|||
Add the pagination headers to your responses ||| Controller
after_action { pagy_headers_merge(@pagy) if @pagy }
|||
Render your JSON response as usual ||| Controller action
render json: { data: @records }
||| +++