[英]Rails and Pagy pagination
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.在 config/initializers/pagy.rb 中。
Nevertheless, if I enter the address localhost:3000/cars?items=1000, I get 1000 results.不过,如果我输入地址 localhost:3000/cars?items=1000,我会得到 1000 个结果。 And I expected 50.
我预计50。
How to limit the maximum number of elements that can be retrieved?如何限制可以检索的最大元素数?
Pagy version 3.13 Rails version 6.1.3 Pagy 版本 3.13 Rails 版本 6.1.3
Regards问候
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.如果你在
config/initializers/pagy.rb
中设置它,它不会立即加载,所以它使用旧配置运行,我不知道为什么,我怀疑缓存引擎。
So you can set it in the controller, example with mine app/controllers/pages_controller.rb所以你可以在 controller 中设置它,例如我的 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!它会正常工作,将最大项目限制为 50!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.