Module: Undercarriage::Controllers::KaminariConcern

Extended by:
ActiveSupport::Concern
Defined in:
lib/undercarriage/controllers/kaminari_concern.rb

Overview

Kaminari pagination

Helpers for Kaminari style pagination. Note that the Kaminari gem is not loaded with dependency. It must be added to your own Gemfile

Examples:

Controller

class ExamplesController < ApplicationController
  include Undercarriage::Controllers::KaminariConcern

  def index
    @examples = Examples.page(page_num).per(per_page)
  end
end

Instance Method Summary collapse

Instance Method Details

#page_numInteger

Page number

Will look for the Kaminari config param_name (typically page) in the URL paramaters.

This is asseccible from the View as page_num

Examples:

Request

# GET /examples?page=5 # Return page 5 of items
# GET /examples?per=10&page=3 # Return page 3 of items with 10 items per page

Returns:

  • (Integer)

    the page number



56
57
58
# File 'lib/undercarriage/controllers/kaminari_concern.rb', line 56

def page_num
  params.fetch(page_num_key, page_num_default).to_i
end

#per_pageInteger

Items per page

The number of items to return in pagination. Will use the Kaminari config default_per_page (typically 25) for the count and will look for per in the URL paramaters to override.

This is asseccible from the View as per_page

Examples:

Request

# GET /examples?per=100 # Return 100 items per page
# GET /examples?per=10&page=3 # Return page 3 of items with 10 items per page

Returns:

  • (Integer)

    the number of items per page



40
41
42
# File 'lib/undercarriage/controllers/kaminari_concern.rb', line 40

def per_page
  params.fetch(per_page_key, per_page_default).to_i
end