Module | WillPaginate::ViewHelpers |
In: |
lib/will_paginate/view_helpers.rb
|
The main view helper, will_paginate, renders pagination links for the given collection. The helper itself is lightweight and serves only as a wrapper around LinkRenderer instantiation; the renderer then does all the hard work of generating the HTML.
Options for pagination helpers are optional and get their default values from the WillPaginate::ViewHelpers.pagination_options hash. You can write to this hash to override default options on the global level:
WillPaginate::ViewHelpers.pagination_options[:previous_label] = 'Previous page'
By putting this into "config/initializers/will_paginate.rb" (or simply environment.rb in older versions of Rails) you can easily translate link texts to previous and next pages, as well as override some other defaults to your liking.
Renders a helpful message with numbers of displayed vs. total entries. You can use this as a blueprint for your own, similar helpers.
<%= page_entries_info @posts %> #-> Displaying posts 6 - 10 of 26 in total
By default, the message will use the humanized class name of objects in collection: for instance, "project types" for ProjectType models. Override this with the :entry_name parameter:
<%= page_entries_info @posts, :entry_name => 'item' %> #-> Displaying items 6 - 10 of 26 in total
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).
Renders Digg/Flickr-style pagination for a WillPaginate::Collection object. Nil is returned if there is only one page in total; no point in rendering the pagination in that case…
Display options:
HTML options:
Advanced options:
All options not recognized by will_paginate will become HTML attributes on the container element for pagination links (the DIV). For example:
<%= will_paginate @posts, :style => 'font-size: small' %>
… will result in:
<div class="pagination" style="font-size: small"> ... </div>
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>