Sha256: 08bb45502db1a17dba6ac4efcbabe1e3983dddaaacde0193acda30e8593c035b

Contents?: true

Size: 917 Bytes

Versions: 30

Compression:

Stored size: 917 Bytes

Contents

module Rao
  module ResourcesController::WillPaginateConcern
    extend ActiveSupport::Concern

    included do
      helper_method :paginate?
    end

    def paginate?
      true
    end

    private

    def load_collection
      options = { page: params[:page] }
      options[:per_page] = per_page
      @collection = load_collection_scope.paginate(options)
    end

    def per_page
      # Return page size from configuration if per_page is not present in params
      unless params.has_key?(:per_page)
        Rao::ResourcesController::Configuration.pagination_per_page_default
      end

      # Return count of all records or nil if no records present if
      # params[:per_page] equals 'all'. Otherwise return params[:per_page]
      if params[:per_page] == 'all'
        count = load_collection_scope.count
        count > 0 ? count : nil
      else
        params[:per_page]
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
rao-resources_controller-0.0.52.pre app/concerns/rao/resources_controller/will_paginate_concern.rb
rao-resources_controller-0.0.51.pre app/concerns/rao/resources_controller/will_paginate_concern.rb
rao-resources_controller-0.0.50.pre app/concerns/rao/resources_controller/will_paginate_concern.rb
rao-resources_controller-0.0.49.pre app/concerns/rao/resources_controller/will_paginate_concern.rb
rao-resources_controller-0.0.48.pre app/concerns/rao/resources_controller/will_paginate_concern.rb
rao-resources_controller-0.0.47.pre app/concerns/rao/resources_controller/will_paginate_concern.rb
rao-resources_controller-0.0.46.pre app/concerns/rao/resources_controller/will_paginate_concern.rb
rao-resources_controller-0.0.45.pre app/concerns/rao/resources_controller/will_paginate_concern.rb
rao-resources_controller-0.0.44.pre app/concerns/rao/resources_controller/will_paginate_concern.rb
rao-resources_controller-0.0.43.pre app/concerns/rao/resources_controller/will_paginate_concern.rb
rao-resources_controller-0.0.42.pre app/concerns/rao/resources_controller/will_paginate_concern.rb
rao-resources_controller-0.0.41.pre app/concerns/rao/resources_controller/will_paginate_concern.rb
rao-resources_controller-0.0.40.pre app/concerns/rao/resources_controller/will_paginate_concern.rb
rao-resources_controller-0.0.39.pre app/concerns/rao/resources_controller/will_paginate_concern.rb
rao-resources_controller-0.0.38.pre app/concerns/rao/resources_controller/will_paginate_concern.rb
rao-resources_controller-0.0.37.pre app/concerns/rao/resources_controller/will_paginate_concern.rb
rao-resources_controller-0.0.36.pre app/concerns/rao/resources_controller/will_paginate_concern.rb
rao-resources_controller-0.0.35.pre app/concerns/rao/resources_controller/will_paginate_concern.rb
rao-resources_controller-0.0.34.pre app/concerns/rao/resources_controller/will_paginate_concern.rb
rao-resources_controller-0.0.33.pre app/concerns/rao/resources_controller/will_paginate_concern.rb