gitlab-org--gitlab-foss/app/controllers/concerns/paginated_collection.rb
Markus Koller f1926b321d
Add controller concern for paginated collections
We had similar code in a few places to redirect to the last page if
the given page number is out of range. This unifies the handling in a
new controller concern and adds usage of it in all snippet listings.
2019-09-10 15:24:29 +02:00

19 lines
415 B
Ruby

# 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