Module: PageLimiter

Extended by:
ActiveSupport::Concern
Included in:
Explore::ProjectsController
Defined in:
app/controllers/concerns/page_limiter.rb

Overview

Include this in your controller and call ‘limit_pages` in order to configure the limiter.

Examples:
  class MyController < ApplicationController
    include PageLimiter

    before_action only: [:index] do
      limit_pages(500)
    end

    # You can override the default response
    rescue_from PageOutOfBoundsError, with: :page_out_of_bounds

    def page_out_of_bounds(error)
      # Page limit number is available as error.message
      head :ok
    end

Constant Summary collapse

PageLimiterError =
Class.new(StandardError)
PageLimitNotANumberError =
Class.new(PageLimiterError)
PageLimitNotSensibleError =
Class.new(PageLimiterError)
PageOutOfBoundsError =
Class.new(PageLimiterError)

Instance Method Summary collapse

Instance Method Details

#limit_pages(max_page_number) ⇒ Object



35
36
37
# File 'app/controllers/concerns/page_limiter.rb', line 35

def limit_pages(max_page_number)
  check_page_number!(max_page_number)
end