Class Ramaze::Pager
In: lib/ramaze/helper/pager.rb
Parent: Object

Displays a collection of entitities in multiple pages.

Design

This pager is carefully designed for scaleability. It stores only the items for one page. The key parameter is needed, multiple pagers can coexist in a single page. The pager leverages the SQL LIMIT option to optimize database interaction.

Example

  class MyController
    def index
      objs = (0..200).to_a
      @entries, @pager = paginate(objs, :limit => 20)
    end
  end

  <html>
    <head><title>Pager</title></head>
    <body>
      <?r if pager.navigation? ?>
        <div class="pager">#{@pager.navigation}</div>
      <?r end ?>
      <ul>
      <?r @entries.each do |entry| ?>
        <li>#{entry}</li>
      <?r end ?>
      </ul>
    </body>
  </html>

Styling

The following classes can be used for styling with CSS (provided you put the pager in a element with class ‘pager’ like shown above):

  .pager {}
  .pager .first {}
  .pager .previous {}
  .pager .next {}
  .pager .last {}
  .pager ul {}
  .pager li {}
  .pager li.active {}

Methods

Included Modules

Ramaze::Helper::Link Ramaze::Traited

Attributes

limit  [R]  Items per page.
page  [R]  The current page.
page_count  [R]  The total number of pages.
total_count  [R]  Total count of items.

Public Class methods

Create a new Pager object.

request:Ramaze::Request object providing access to GET parameters
limit:how many elements go to one page
total_count:total element count
key:key used for getting the current page from GET paramaters

Note: You never have to create this class yourself, use the `paginate()` convenience method from the Helper::Pager.

Public Instance methods

Returns each element for the current page

Iterator Returns 1-based index.

Is the pager empty, ie has one page only?

Return the first page index.

Is the first page displayed?

Return the last page index.

Is the last page displayed?

To be used with Og queries.

Override this method in your application if needed.

Returns true if a navigation is necessary (meaning there is more than one page)

Return the index of the next page.

Returns the index of the first element to go into the current page

Return the index of the previous page.

Returns the amount of all elements in all pages.

[Validate]