Rails pagy route without pagination

105 views Asked by At

I have a Rails API app. I use Pagy nicely and works perfectly. However, I would like to call the same route|service|endpoint for getting all records, ignoring pagination. Is this possible?

2

There are 2 answers

0
Hemangini Gohel On

You can pass a flag as query params and based on input you can set/ignore pagination

0
rnwed_user On

it would be able to work with an extra param, in this case we will use params[:show_all]

def index
  unless params[:show_all]
    @pagy, @products = pagy(Product.kept, items: page_size, page: page_number)
        render json: @products
  else
    Product.kept
  end
end