module Undercarriage::Controllers::KaminariConcern

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

Usage

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

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

Public Instance Methods

page_num() click to toggle source

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`

Usage

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

@return [Integer] the page number

# File lib/undercarriage/controllers/kaminari_concern.rb, line 59
def page_num
  params.fetch(page_num_key, page_num_default).to_i
end
per_page() click to toggle source

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`

Usage

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

@return [Integer] the number of items per page

# File lib/undercarriage/controllers/kaminari_concern.rb, line 42
def per_page
  params.fetch(per_page_key, per_page_default).to_i
end

Protected Instance Methods

page_num_key() click to toggle source

Page numberkey

Query param to be used to identify page offset

# File lib/undercarriage/controllers/kaminari_concern.rb, line 79
def page_num_key
  Kaminari.config.param_name
end
per_page_key() click to toggle source

Items per page key

Query param to be used to identify count to be returned

# File lib/undercarriage/controllers/kaminari_concern.rb, line 70
def per_page_key
  :per
end

Private Instance Methods

page_num_default() click to toggle source
# File lib/undercarriage/controllers/kaminari_concern.rb, line 89
def page_num_default
  1
end
per_page_default() click to toggle source
# File lib/undercarriage/controllers/kaminari_concern.rb, line 85
def per_page_default
  Kaminari.config.default_per_page
end