From 2f01d2a5d4d3379cbae1daddd2a675d8f8b8ac59 Mon Sep 17 00:00:00 2001 From: Bohung Date: Sat, 5 Mar 2022 23:11:48 +0800 Subject: [PATCH] Fix gallery index pagination bug. --- app/controllers/galleries_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/galleries_controller.rb b/app/controllers/galleries_controller.rb index 5f48330..64463fe 100644 --- a/app/controllers/galleries_controller.rb +++ b/app/controllers/galleries_controller.rb @@ -147,7 +147,10 @@ class GalleriesController < ApplicationController end else albums_with_order = [] - start_index = (page_data_count - (with_order_count % page_data_count) + page_data_count*(page_no - 1 - with_order_total_pages)) + start_index = page_data_count*(page_no - 1 - with_order_total_pages) + if with_order_count != 0 + start_index += (page_data_count - (with_order_count % page_data_count)) + end albums_no_order = album_tp.desc(:created_at).where(:order.in=>[-1,nil]).page(nil).per(all_count)[start_index...(start_index+page_data_count)].to_a end albums = albums_with_order.concat(albums_no_order)