I'm trying to figure out how to paginate a collection that I run
through a "group_by" call (that's part of Rails, not the group_by SQL
For example, let's say that I have 100 users in my system and I want
to list them, 10 to a page, and grouped by their state (US state, not
AASM state). So let's say that I have 7 users from Colorado, but
alphabetically, only two of them are in the first 10 returned.
If I paginate first, then group, I'll end up with page 1 showing CO
with 2 users, then some future page showing CO again. If I group
first, I'll have all 7 CO users grouped together, but then I don't
know how to paginate it? Cause let's say that instead of 7 there were
12 users from CO... it should show CO and the first 10, then on the
next page show CO and the last 2.
Has anyone else run into something similar? How do you handle it? I
know conceptually I want to group first then paginate, but the
grouping becomes a nested array (actually, it appears to be an
"ActiveSupport::OrderedHash") and paginate doesn't work on it:
NoMethodError: undefined method `paginate' for
Is there a better way to think about this? If, for example, group one
has 6 users and group two has 7 users and I'm paginating 10 per page,
it should show "Group One" and have 6 users listed, then show "Group
Two" and have 4 users listed. Then the next page should show "Group
Two" and have the last 3 users listed, then "Group Three", etc.