summaryrefslogtreecommitdiff
path: root/app/controllers/concerns/paginated_collection.rb
blob: fcee44933142e0fb63f6cb6f270919b068e28fcc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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 == 0

    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