class Kaminari::Helpers::Tag

A tag stands for an HTML tag inside the paginator. Basically, a tag has its own partial template file, so every tag can be rendered into String using its partial template.

The template file should be placed in your app/views/kaminari/ directory with underscored class name (besides the “Tag” class. Tag is an abstract class, so _tag partial is not needed).

e.g.)  PrevLink  ->  app/views/kaminari/_prev_link.html.erb

When no matching template were found in your app, the engine's pre installed template will be used.

e.g.)  Paginator  ->  $GEM_HOME/kaminari-x.x.x/app/views/kaminari/_paginator.html.erb

Public Instance Methods

page_url_for(page) click to toggle source
# File lib/kaminari/helpers/tags.rb, line 36
def page_url_for(page)
  params = params_for(page)
  params[:only_path] = true
  @template.url_for params
end

Private Instance Methods

params_for(page) click to toggle source
# File lib/kaminari/helpers/tags.rb, line 44
def params_for(page)
  page_params = Rack::Utils.parse_nested_query("#{@param_name}=#{page}")
  page_params = @params.deep_merge(page_params)

  if !Kaminari.config.params_on_first_page && (page <= 1)
    # This converts a hash:
    #   from: {other: "params", page: 1}
    #     to: {other: "params", page: nil}
    #   (when @param_name == "page")
    #
    #   from: {other: "params", user: {name: "yuki", page: 1}}
    #     to: {other: "params", user: {name: "yuki", page: nil}}
    #   (when @param_name == "user[page]")
    @param_name.to_s.scan(/[\w\.]+/)[0..-2].inject(page_params){|h, k| h[k] }[$&] = nil
  end

  page_params
end
partial_path() click to toggle source
# File lib/kaminari/helpers/tags.rb, line 63
def partial_path
  [
   @views_prefix,
   "kaminari",
   @theme,
   self.class.name.demodulize.underscore
  ].compact.join("/")
end