Module: WillPaginate::ActionView

### Home Classes Methods

### In Files

- lib/will_paginate/view_helpers/action_view.rb

### Namespace

- CLASS WillPaginate::ActionView::LinkRenderer

### Methods

- #infer_collection_from_controller
- #paginated_section
- #will_paginate_translate

### Included Modules

- WillPaginate::ViewHelpers

### Class/Module Index

Quicksearch

- WillPaginate
- WillPaginate::ActionView
- WillPaginate::ActionView::LinkRenderer
- WillPaginate::ActiveRecord
- WillPaginate::ActiveRecord::BaseMethods
- WillPaginate::ActiveRecord::Pagination
- WillPaginate::ActiveRecord::RelationMethods
- WillPaginate::Collection
- WillPaginate::CollectionMethods
- WillPaginate::DataMapper
- WillPaginate::DataMapper::CollectionMethods
- WillPaginate::DataMapper::Pagination
- WillPaginate::Deprecation
- WillPaginate::Deprecation::Hash
- WillPaginate::I18n
- WillPaginate::InvalidPage
- WillPaginate::Merb
- WillPaginate::Merb::LinkRenderer
- WillPaginate::PageNumber
- WillPaginate::PerPage
- WillPaginate::PerPage::Inheritance
- WillPaginate::Railtie
- WillPaginate::Railtie::ControllerRescuePatch
- WillPaginate::Railtie::ShowExceptionsPatch
- WillPaginate::SequelMethods
- WillPaginate::Sinatra
- WillPaginate::Sinatra::Helpers
- WillPaginate::Sinatra::LinkRenderer
- WillPaginate::ViewHelpers
- WillPaginate::ViewHelpers::LinkRenderer
- WillPaginate::ViewHelpers::LinkRendererBase
- Array
- Object

No matching classes.

# 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.