From cae65996313fc266ff1eac53a3c9a7958f3d59e1 Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 7 Jan 2022 14:17:48 -0600 Subject: [PATCH] pagination: fix paginator regression caused by Rails 7. Fix the paginator not detecting the first or last page correctly during sequential pagination. Caused by the fact that we fetch one more record than needed to detect whether we're on the last page, then throw that record away by overriding Rails' internal `records` method. An upstream refactoring meant that the `size` method now counts the number of records *after* the extra record is thrown away, where before it counted *before* the extra record was thrown away. --- app/logical/pagination_extension.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/logical/pagination_extension.rb b/app/logical/pagination_extension.rb index ee4722ead..b5d7b4903 100644 --- a/app/logical/pagination_extension.rb +++ b/app/logical/pagination_extension.rb @@ -82,7 +82,8 @@ module PaginationExtension when :sequential_before false when :sequential_after - size <= records_per_page + load + @records.size <= records_per_page end end @@ -91,7 +92,8 @@ module PaginationExtension when :numbered current_page >= total_pages when :sequential_before - size <= records_per_page + load + @records.size <= records_per_page when :sequential_after false end