Using Pagy::Backend outside of a Controller #760
excid3
started this conversation in
Feature Requests
Replies: 1 comment 11 replies
-
Hi @excid3, That said, if instead of passing the This should do that: def collection(params)
pagy associated_records, **params
end Makes sense? |
Beta Was this translation helpful? Give feedback.
11 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hey @ddnexus! 👋
Yesterday, I was working on Madmin to add pagination to has_many associations and needed to add Pagy inside a class outside the controller. I got it working with a small change, but thought I would bring it up as a suggestion that Pagy might consider supporting out of the box.
The gist of it is this:
Here's the actual commit in Madmin for more specifics: excid3/madmin@f5c618b#diff-9e38fefc7cbc18013d71df9a04d89ef3c66614ad5521b67d0dd1f74c65db5220R34
Proposal:
Check vars for params key otherwise fallback to params method in
Pagy::Backend
.Something like:
I imagine this isn't that common (first time I've needed something like this) but it saves me a lot of trouble so I can keep using
Pagy::Backend
without any changes for compatibility with any future changes.Beta Was this translation helpful? Give feedback.
All reactions