Home > Blockchain >  Rails pagy route without pagination
Rails pagy route without pagination

Time:01-19

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?

CodePudding user response:

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

CodePudding user response:

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
  • Related