module Kaminari::Helpers::UrlHelper

The Kaminari::Helpers::UrlHelper module provides useful methods for generating a path or url to a particlar page. A class must implement the following methods:

* <tt>url_for</tt>: A method that generates an actual path
* <tt>params</tt>: A method that returns query string parameters
* <tt>request</tt>: A method that returns a Rack::Request object

A normal Rails controller implements all the methods, which makes it trivial to use this module:

Examples

class UsersController < ApplicationController
  include Kaminari::Helpers::UrlHelper

  def index
   @users = User.page(1)

   path_to_next_page(@items)
   # => /items?page=2
  end
end

Public Instance Methods

next_page_path(scope, options = {}) click to toggle source

A helper that calculates the path to the next page.

Examples

Basic usage:

<%= path_to_next_page @items %>
#-> /items?page=2

It will return `nil` if there is no next page.

# File lib/kaminari/helpers/helper_methods.rb, line 70
def next_page_path(scope, options = {})
  Kaminari::Helpers::NextPage.new(self, **options.reverse_merge(current_page: scope.current_page)).url if scope.next_page
end
Also aliased as: path_to_next_page
next_page_url(scope, options = {}) click to toggle source

A helper that calculates the url to the next page.

Examples

Basic usage:

<%= next_page_url @items %>
#-> http://www.example.org/items?page=2

It will return `nil` if there is no next page.

# File lib/kaminari/helpers/helper_methods.rb, line 40
def next_page_url(scope, options = {})
  "#{request.base_url}#{next_page_path(scope, options)}" if scope.next_page
end
Also aliased as: path_to_next_url
path_to_next_page(scope, options = {})
Alias for: next_page_path
path_to_next_url(scope, options = {})
Alias for: next_page_url
path_to_prev_page(scope, options = {})
Alias for: prev_page_path
path_to_previous_page(scope, options = {})
Alias for: prev_page_path
prev_page_path(scope, options = {}) click to toggle source

A helper that calculates the path to the previous page.

Examples

Basic usage:

<%= path_to_prev_page @items %>
#-> /items

It will return `nil` if there is no previous page.

# File lib/kaminari/helpers/helper_methods.rb, line 84
def prev_page_path(scope, options = {})
  Kaminari::Helpers::PrevPage.new(self, **options.reverse_merge(current_page: scope.current_page)).url if scope.prev_page
end
prev_page_url(scope, options = {}) click to toggle source

A helper that calculates the url to the previous page.

Examples

Basic usage:

<%= prev_page_url @items %>
#-> http://www.example.org/items

It will return `nil` if there is no previous page.

# File lib/kaminari/helpers/helper_methods.rb, line 54
def prev_page_url(scope, options = {})
  "#{request.base_url}#{prev_page_path(scope, options)}" if scope.prev_page
end
previous_page_path(scope, options = {})
Alias for: prev_page_path
previous_page_url(scope, options = {})
Alias for: prev_page_url
url_to_prev_page(scope, options = {})
Alias for: prev_page_url
url_to_previous_page(scope, options = {})
Alias for: prev_page_url