Sha256: efd7984d715dd0655ff0e7b2734888004a947db7cd1714da3fe81f878389b71e

Contents?: true

Size: 856 Bytes

Versions: 56

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

      10
    end
  end
end

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
udongo-7.9.0 app/controllers/concerns/pagination_controller.rb
udongo-7.8.1 app/controllers/concerns/pagination_controller.rb
udongo-7.8.0 app/controllers/concerns/pagination_controller.rb
udongo-7.7.2 app/controllers/concerns/pagination_controller.rb
udongo-7.7.1 app/controllers/concerns/pagination_controller.rb
udongo-7.7.0 app/controllers/concerns/pagination_controller.rb
udongo-7.6.2 app/controllers/concerns/pagination_controller.rb
udongo-7.6.1 app/controllers/concerns/pagination_controller.rb
udongo-7.6.0 app/controllers/concerns/pagination_controller.rb
udongo-7.5.1 app/controllers/concerns/pagination_controller.rb
udongo-7.5.0 app/controllers/concerns/pagination_controller.rb
udongo-7.4.2 app/controllers/concerns/pagination_controller.rb
udongo-7.4.1 app/controllers/concerns/pagination_controller.rb
udongo-7.4.0 app/controllers/concerns/pagination_controller.rb
udongo-7.3.5 app/controllers/concerns/pagination_controller.rb
udongo-7.3.4 app/controllers/concerns/pagination_controller.rb
udongo-7.3.3 app/controllers/concerns/pagination_controller.rb
udongo-7.3.2 app/controllers/concerns/pagination_controller.rb
udongo-7.3.1 app/controllers/concerns/pagination_controller.rb
udongo-7.2.1 app/controllers/concerns/pagination_controller.rb