mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-10 23:07:47 +00:00
add pagination data concern
This commit is contained in:
18
app/controllers/concerns/pagination_data.rb
Normal file
18
app/controllers/concerns/pagination_data.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module PaginationData
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def pagination_data(objects, default_page: nil, default_per_page: nil)
|
||||
{
|
||||
results: objects.total_count,
|
||||
pages: objects.num_pages,
|
||||
page: (params[:page] || default_page).to_i,
|
||||
per_page: (params[:per_page] || default_per_page).to_i
|
||||
}
|
||||
end
|
||||
|
||||
def pagination_required?
|
||||
params[:page].present? || params[:per_page].present?
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user