summaryrefslogtreecommitdiff
path: root/app/controllers/concerns/paginated_collection.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/concerns/paginated_collection.rb')
-rw-r--r--app/controllers/concerns/paginated_collection.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/app/controllers/concerns/paginated_collection.rb b/app/controllers/concerns/paginated_collection.rb
new file mode 100644
index 00000000000..be84215a9e2
--- /dev/null
+++ b/app/controllers/concerns/paginated_collection.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+module PaginatedCollection
+ extend ActiveSupport::Concern
+
+ private
+
+ def redirect_out_of_range(collection, total_pages = collection.total_pages)
+ return false if total_pages.zero?
+
+ out_of_range = collection.current_page > total_pages
+
+ if out_of_range
+ redirect_to(url_for(safe_params.merge(page: total_pages, only_path: true)))
+ end
+
+ out_of_range
+ end
+end