syedsibtain
Tue Dec 17 2024
When working with paginated data in Ruby on Rails, we might encounter situations where we need to paginate an array rather than an Active Record collection. The
Require the Pagy Extras Array:
And then use the
#rubyonrails #pagination #pagy
pagy
gem provides an efficient and flexible way to handle pagination, and it includes an extras/array
feature specifically for arrays.Require the Pagy Extras Array:
# config/initializers/pagy.rb
require "pagy/extras/array"
And then use the
pagy_array
method to paginate your array in the controller
def index
// some code
@pagy, @purchase_order_attachments = pagy_array(orders_with_attachments, items: params[:limit] || 10)
end
#rubyonrails #pagination #pagy