Rails and Pagy pagination

1.3k Views Asked by At

How to set the maximum number of items that can be downloaded.

I set:

require 'pagy/extras/items'
Pagy::VARS[:max_items] = 50 

in config/initializers/pagy.rb.

Nevertheless, if I enter the address localhost:3000/cars?items=1000, I get 1000 results. And I expected 50.

How to limit the maximum number of elements that can be retrieved?

Pagy version 3.13 Rails version 6.1.3

Regards

1

There are 1 best solutions below

2
protoproto On

If you set it in the config/initializers/pagy.rb, it will not load instantly and so, it runs with old configs, I don't know why, I doubt the cache engine.

So you can set it in the controller, example with mine app/controllers/pages_controller.rb

class PagesController < ApplicationController
  def home
    Pagy::VARS[:max_items] = 50 # Set the value you want!
    @pagy, @records = pagy(Car.all)
  end
end

It will work fine, limit the max items to 50!