Included Modules

WillPaginate::ActionView

ActionView helpers

This module serves for availability in ActionView templates. It also adds a new view helper: paginated_section.

Using the helper without arguments

If the helper is called without passing in the collection object, it will try to read from the instance variable inferred by the controller name. For example, calling will_paginate while the current controller is PostsController will result in trying to read from the @posts variable. Example:

<%= will_paginate :id => true %>

... will result in @post collection getting paginated:

<div class="pagination" id="posts_pagination"> ... </div>

Public Instance Methods

paginated_section(*args, &block) click to toggle source

Wrapper for rendering pagination links at both top and bottom of a block of content.

<% paginated_section @posts do %>
  <ol id="posts">
    <% for post in @posts %>
      <li> ... </li>
    <% end %>
  </ol>
<% end %>

will result in:

<div class="pagination"> ... </div>
<ol id="posts">
  ...
</ol>
<div class="pagination"> ... </div>

Arguments are passed to a will_paginate call, so the same options apply. Don't use the :id option; otherwise you'll finish with two blocks of pagination links sharing the same ID (which is invalid HTML).

# File lib/will_paginate/view_helpers/action_view.rb, line 65
def paginated_section(*args, &block)
  pagination = will_paginate(*args)
  if pagination
    pagination + capture(&block) + pagination
  else
    capture(&block)
  end
end
will_paginate_translate(keys, options = {}) click to toggle source
# File lib/will_paginate/view_helpers/action_view.rb, line 74
def will_paginate_translate(keys, options = {})
  if respond_to? :translate
    if Array === keys
      defaults = keys.dup
      key = defaults.shift
    else
      defaults = nil
      key = keys
    end
    translate(key, options.merge(:default => defaults, :scope => :will_paginate))
  else
    super
  end
end

Protected Instance Methods

infer_collection_from_controller() click to toggle source
# File lib/will_paginate/view_helpers/action_view.rb, line 91
def infer_collection_from_controller
  collection_name = "@#{controller.controller_name}"
  collection = instance_variable_get(collection_name)
  raise ArgumentError, "The #{collection_name} variable appears to be empty. Did you " +
    "forget to pass the collection object for will_paginate?" if collection.nil?
  collection
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.