In my Rails 7 app I'm using Pagy gem for pagination. The pagination works well but now I want to give the user the ability to choose how many items they will see in the paginated list. According to the docs the implementation should be fairly easy:
# initializers/pagy.rb
require 'pagy/extras/items'
# Instance variables
Pagy::DEFAULT[:items] = 10
Pagy::DEFAULT[:items_param] = :items
with sample controller:
class PaymentsController < ApplicationController
def index
@pagy, @payments = pagy_array(fetch_payments)
end
private
def client
@client ||= Test::Client.new
end
def fetch_payments
client.payments.list(
page: 1,
per_page: 100,
platform_id: current_user.platform_id,
)
end
end
But now I don't know how to create working dropdown (like this one) with paginated results inside the view.
in /config/initializers/pagy.rb
in your /app/controllers/your_controller.rb
in your app/view