cartodb-4.42/app/models/carto/paged_model.rb

16 lines
389 B
Ruby
Raw Normal View History

2024-04-06 13:25:13 +08:00
module Carto
module PagedModel
def paged(page = 1, per_page = 20, order = nil)
self.paged_association(self, page, per_page, order)
end
def self.paged_association(association, page = 1, per_page = 20, order = nil)
paged = association.offset((page - 1) * per_page).limit(per_page)
paged = paged.order(order) unless order.nil?
paged
end
end
end