diff --git a/lib/universal_paginator.rb b/lib/universal_paginator.rb index e7a0dadec..ae6c6ff1b 100644 --- a/lib/universal_paginator.rb +++ b/lib/universal_paginator.rb @@ -4,13 +4,18 @@ class UniversalPaginator < JSONAPI::Paginator attr_reader :params def initialize(params) + super @params = params # Initialize sub-paginator paginator end def offset? - params[:offset].present? || params[:limit].present? + if params&.fetch(:offset, nil) || params&.fetch(:limit, nil) + true + else + false + end end def page? @@ -32,10 +37,12 @@ def apply(relation, _order_options) if offset? paginator.apply(relation, _order_options) else + params = params.to_h # We apply the PagedPaginator logic ourselves because it uses offset/limit # We want to have page/per method calls to be applied to the relation relation = relation.page(params[:number]) if params[:number].present? relation = relation.per(params[:size]) if params[:size].present? + relation end end end