-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Usage with api-pagination and pagy #11
Comments
For now I was able to monkey-patch my way out of this issue by simply adding this to the controller: module ApiPagination
class << self
def paginate_with_pagy(collection, options)
if Pagy::DEFAULT[:max_per_page] && options[:per_page] > Pagy::DEFAULT[:max_per_page]
options[:per_page] = Pagy::DEFAULT[:max_per_page]
elsif options[:per_page] <= 0
options[:per_page] = Pagy::DEFAULT[:items]
end
pagy = pagy_from(collection, options)
collection = if collection.respond_to?(:offset) && collection.respond_to?(:limit)
collection.offset(pagy.offset).limit(pagy.items).fast_page
else
collection[pagy.offset, pagy.items]
end
return [collection, pagy]
end
end
end Notice the addition lf But there is probably a cleaner way to do this… |
Thanks @slhck! I'm going to look at this more when I have a chance. I'm expecting your way of overriding the method is probably best. Also possible pagy may have changed since I last used it with fast_page. I'll see if I can find a nicer way, if not, will update the readme. |
This is more of a question about the usage of this Gem.
I am using
api-pagination
in combination withpagy
to provide a paginated API.This might be as simple as the example shown here.
Internally
api-pagination
callspagy
viaPagy.new
; here you can also see the offset and limit being applied.How would I make this work with
fast_page
?When I add the method from the README to my controller, it is not being called.
The text was updated successfully, but these errors were encountered: