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

each each_with_index empty? first_page first_page? last_page last_page? limit navigation navigation? new next_page offset prev_page size

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

new(request, limit, total_count, key = trait[:key])

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

each(&block)

Returns each element for the current page

each_with_index(&block)

Iterator Returns 1-based index.

empty?()

Is the pager empty, ie has one page only?

first_page()

Return the first page index.

first_page?()

Is the first page displayed?

last_page()

Return the last page index.

last_page?()

Is the last page displayed?

limit()

To be used with Og queries.

navigation()

Override this method in your application if needed.

navigation?()

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

next_page()

Return the index of the next page.

offset()

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

prev_page()

Return the index of the previous page.

size()

Returns the amount of all elements in all pages.

[Validate]