Sha256: 882598c63c34dfc27e97f621db93b115ce65d05ea27799bee531787a5269b699

Contents?: true

Size: 856 Bytes

Versions: 16

Compression:

Stored size: 856 Bytes

Contents

require 'will_paginate/array'

module Concerns
  module PaginationController
    extend ActiveSupport::Concern

    included do
      # The respond_to? is added because of issues in our specs.
      if respond_to?(:helper_method)
        helper_method :per_page, :page_number
      end
    end

    def page_number
      return 1 unless params[:page].respond_to?(:to_i)
      page = params[:page].to_i.abs
      page == 0 ? 1 : page
    end

    def paginate(records, options = {})
      options.reverse_merge!(page: page_number, per_page: per_page)

      if records.is_a?(Array)
        records.paginate options
      else
        records.page(options[:page]).per_page(options[:per_page])
      end
    end

    def per_page
      [5, 10, 25, 30, 50, 100].each do |i|
        return i if params[:per_page].to_i == i
      end

      30
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
udongo-5.0.2 app/controllers/concerns/pagination_controller.rb
udongo-5.0.1 app/controllers/concerns/pagination_controller.rb
udongo-5.0.0 app/controllers/concerns/pagination_controller.rb
udongo-4.0.0 app/controllers/concerns/pagination_controller.rb
udongo-3.0.0 app/controllers/concerns/pagination_controller.rb
udongo-2.0.4 app/controllers/concerns/pagination_controller.rb
udongo-2.0.3 app/controllers/concerns/pagination_controller.rb
udongo-2.0.2 app/controllers/concerns/pagination_controller.rb
udongo-2.0.1 app/controllers/concerns/pagination_controller.rb
udongo-2.0.0 app/controllers/concerns/pagination_controller.rb
udongo-1.0.4 app/controllers/concerns/pagination_controller.rb
udongo-1.0.3 app/controllers/concerns/pagination_controller.rb
udongo-1.0.2 app/controllers/concerns/pagination_controller.rb
udongo-1.0.1 app/controllers/concerns/pagination_controller.rb
udongo-1.0.0 app/controllers/concerns/pagination_controller.rb
udongo-0.1.0 app/controllers/concerns/pagination_controller.rb