From fd300a75d3007f711090967787ad6510ab132f87 Mon Sep 17 00:00:00 2001 From: Oleg Valter Date: Mon, 30 Oct 2023 12:29:41 +0300 Subject: [PATCH 1/4] 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/4] @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/4] 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 From 58ae047aaaf558ef8c3fe6dd39d23a9a0b1d0faf Mon Sep 17 00:00:00 2001 From: Oleg Valter Date: Thu, 24 Jul 2025 07:12:01 +0300 Subject: [PATCH 4/4] starting from scratch: just add pagination to the view --- app/views/post_history/post.html.erb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/views/post_history/post.html.erb b/app/views/post_history/post.html.erb index 3444c67c9..eaf86e945 100644 --- a/app/views/post_history/post.html.erb +++ b/app/views/post_history/post.html.erb @@ -70,3 +70,7 @@ <% end %> <% end %> + +
+ <%= will_paginate @history, renderer: BootstrapPagination::Rails %> +