現在 Gem 也開始比速度了嗎。。。
https://github.com/ddnexus/pagy
Features
Straightforward code
Pagy is just ~100 lines of simple ruby, organized in 3 flat modules very easy to understand and use it produces its own HTML, URLs, pluralization and interpolation with its own specialized and fast code 100% of its methods are public API, accessible and overridable right where you use them (no need of monkey patching or subclassing) Totally agnostic
it doesn't need to know anything about your models, ORM or Storage, so it doesn't add any code to them it works with all kinds of collections, even pre-paginated, records, Arrays, JSON data... and just whatever you can count it works with all Rack frameworks (Rails, Sinatra, Padrino, ecc.) out of the box it works with any possible non-Rack environment by just overriding one or two one-liner methods Easy to use
You can use pagy in a quite familiar way:
Paginate your collection in some controller:
@pagy, @records = pagy(Product.some_scope) Render the navigation links with a super-fast helper in some view:
<%== pagy_nav(@pagy) %> Or - if you prefer - render the navigation links with a template:
<%== render 'pagy/nav', locals: {pagy: @pagy} %>