From b242499e45584fb471b94159aed6d264ee10fc31 Mon Sep 17 00:00:00 2001 From: Bohung Date: Sat, 5 Mar 2022 23:16:34 +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 64463fe..0bf2006 100644 --- a/app/controllers/galleries_controller.rb +++ b/app/controllers/galleries_controller.rb @@ -56,7 +56,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)