Rails will_paginate and ajax, paging while the DB table changes-open source projects mislav/will_paginate
I’m trying to use will_paginate for a Rails 3.2 app and I didn’t see any reference anywhere for what happens when someone is paging while the data in the db is changed. More specifically, new records are added.
I might be missing something here, but if I get how it works, will_paginate simply counts the records in the DB. Say I load a page with 5 records at a time and want them ordered by the newest first. A user loads the page and gets records 6-10 (the newest records at that time) showing at page 1. Then, someone inserts another record to the table, id=11. After that, the first user clicks to get to page 2 but now page 2 gives records 2-6. So the user got id=6 in both pages.
This problem doesn’t sound that bad, but it is really bad if you want to use will_paginate paging for an infinite scroll as shown here: http://railscasts.com/episodes/114-endless-page
I thought about adding a time stamp of the first page load and pass it to consecutive ajax calls to filter on the records that were present at first in order to not get the duplicates.
Is there some best practice way to handle this?