简体   繁体   English

没有分页的 Rails pagy 路由

[英]Rails pagy route without pagination

I have a Rails API app.我有一个 Rails API 应用程序。 I use Pagy nicely and works perfectly.我很好地使用了 Pagy ,并且工作得很好。 However, I would like to call the same route|service|endpoint for getting all records, ignoring pagination.但是,我想调用相同的路由|服务|端点来获取所有记录,忽略分页。 Is this possible?这可能吗?

You can pass a flag as query params and based on input you can set/ignore pagination您可以将标志作为查询参数传递,并根据输入设置/忽略分页

it would be able to work with an extra param, in this case we will use params[:show_all]它可以使用额外的参数,在这种情况下我们将使用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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM