(Re: Pagination, You're doing it wrong) - Fixing Duplicate/Missing Records in Infinite Scrolling + Pagination by Hacking the Kaminari Gem
Using pagination with JS to create an infinite scrolling page is common, (Check out this RailsCast episode if you don't know how: http://railscasts.com/episodes/114-endless-page-revised?view=comments ) But it gives rise to the problem of loading duplicate or missing records. (See: https://coderwall.com/p/lkcaag/pagination-you-re-probably-doing-it-wrong) So, how do you solve this? --- I solved the problem by creating a CustomRelation model that builds on Kaminari's paginate helper. In this example, I am creating an infinite scrolling page of 'posts', akin to Facebook. With the Kaminari gem, its 'paginate' helper accepts ActiveRecord::Relation , which should respond to these 3 methods (this, I refer to the Kir Shatrov's post, see bottom): current_page - returns current page number total_pages - returns total number of pages all - returns an array of rows for the current page So, instead of using Kaminari's default Relation, I cre...