We render users in alphabetical fashion with 10 entries per page using will_paginate gem
Assuming we perform an action to activate or deactivate a user in the 2nd page (say user15)
, We would prefer to show user information on the 2nd page itself or should we redirect the user to the first page with default sort criteria here
There is another case where this is becoming problematic:
Assuming there are 31 entries, so 4th page will contain a single entry
, If we delete this user, we can't show the fourth page since no such user exists
In the above scenario, page=4 and per_page=10, but it would fail to render this page
How should we handle these scenarios, should we just show page=1 in any of the above scenarios.
What would be the right thing to do in the above scenario
Can you elaborate on this one please.
You might want to look into cursor pagination. Instead of pages, you have a cursor for the record and fetch everything before / after this cursor. This cursor could for instance be the encoded created_at timestamp.
Cursor pagination has a lot of other advantages over offset pagination too. However,
will_paginatedoes not support cursor pagination so not sure if this is a feasible approach for you.https://github.com/mislav/will_paginate/wiki
https://medium.com/@meganchang_96378/why-facebook-says-cursor-pagination-is-the-greatest-d6b98d86b6c0