Update products_renderer for pagy pagination

This commit is contained in:
Nihal Mohammed
2021-06-30 17:34:57 +05:30
committed by Matt-Yorkley
parent 4187380225
commit 6bd28bcad8

View File

@@ -3,6 +3,8 @@
require 'open_food_network/scope_product_to_hub'
class ProductsRenderer
include Pagy::Backend
class NoProducts < RuntimeError; end
DEFAULT_PER_PAGE = 10
@@ -50,9 +52,15 @@ class ProductsRenderer
end
def filter_and_paginate(query)
query.
ransack(args[:q]).
result
results = query.ransack(args[:q]).result
_pagy, paginated_results = pagy(
results,
page: args[:page] || 1,
items: args[:per_page] || DEFAULT_PER_PAGE
)
paginated_results
end
def distributed_products