From d42ef7d7dc156c7fb44dd30f12319389612cc2db Mon Sep 17 00:00:00 2001 From: evazion Date: Sat, 14 Apr 2018 10:18:20 -0500 Subject: [PATCH] Fix #3642: Issues with sequential pagination. As of Rails 5, overriding `to_a` on an ActiveRecord collection does nothing. We need to override `records` instead. ref: https://github.com/rails/rails/commit/cdd45fa09d76f7c16ccbb6682e672a44f82174a0 --- .../danbooru/paginator/sequential_collection_extension.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/logical/danbooru/paginator/sequential_collection_extension.rb b/app/logical/danbooru/paginator/sequential_collection_extension.rb index 9cee8fc4a..c78da7846 100644 --- a/app/logical/danbooru/paginator/sequential_collection_extension.rb +++ b/app/logical/danbooru/paginator/sequential_collection_extension.rb @@ -19,7 +19,10 @@ module Danbooru end end - def to_a + # XXX Hack: in sequential pagination we fetch one more record than we need + # so that we can tell when we're on the first or last page. Here we override + # a rails internal method to discard that extra record. See #2044, #3642. + def records if sequential_paginator_mode == :before super.first(records_per_page) else