From fd300a75d3007f711090967787ad6510ab132f87 Mon Sep 17 00:00:00 2001 From: Oleg Valter Date: Mon, 30 Oct 2023 12:29:41 +0300 Subject: [PATCH 1/3] expose page & total count of entries in PostHistory controller --- app/controllers/post_history_controller.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/controllers/post_history_controller.rb b/app/controllers/post_history_controller.rb index 80a37de1c..dbc22a209 100644 --- a/app/controllers/post_history_controller.rb +++ b/app/controllers/post_history_controller.rb @@ -6,9 +6,16 @@ def post return not_found end - @history = PostHistory.where(post_id: params[:id]) - .includes(:post_history_type, :user, post_history_tags: [:tag]) - .order(created_at: :desc, id: :desc).paginate(per_page: 20, page: params[:page]) + base_query = PostHistory.where(post_id: params[:id]) + .includes(:post_history_type, :user, post_history_tags: [:tag]) + .order(created_at: :desc, id: :desc) + + @history = base_query.paginate(per_page: 20, page: params[:page]) + + @count = base_query.count + + @page = params[:page].nil? ? 1 : params[:page] + render layout: 'without_sidebar' end end From fc9f8891b408a6dee0cf626e8bec6953407b36f0 Mon Sep 17 00:00:00 2001 From: Oleg Valter Date: Mon, 30 Oct 2023 12:38:30 +0300 Subject: [PATCH 2/3] @page variable should always be an int --- app/controllers/post_history_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/post_history_controller.rb b/app/controllers/post_history_controller.rb index dbc22a209..38641bf5c 100644 --- a/app/controllers/post_history_controller.rb +++ b/app/controllers/post_history_controller.rb @@ -14,7 +14,7 @@ def post @count = base_query.count - @page = params[:page].nil? ? 1 : params[:page] + @page = params[:page].nil? ? 1 : params[:page].to_i render layout: 'without_sidebar' end From 4767da33aabe5a95c1759c2a42a36cc8c9ca0df9 Mon Sep 17 00:00:00 2001 From: Oleg Valter Date: Mon, 30 Oct 2023 12:44:43 +0300 Subject: [PATCH 3/3] expose number of pages in PostHistory controller --- app/controllers/post_history_controller.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/post_history_controller.rb b/app/controllers/post_history_controller.rb index 38641bf5c..8eac41f4c 100644 --- a/app/controllers/post_history_controller.rb +++ b/app/controllers/post_history_controller.rb @@ -10,12 +10,16 @@ def post .includes(:post_history_type, :user, post_history_tags: [:tag]) .order(created_at: :desc, id: :desc) - @history = base_query.paginate(per_page: 20, page: params[:page]) + per_page = 20 + + @history = base_query.paginate(per_page: per_page, page: params[:page]) @count = base_query.count @page = params[:page].nil? ? 1 : params[:page].to_i + @pages = (@count.to_f / per_page).ceil + render layout: 'without_sidebar' end end