Ruby on Rails latest stable (v7.1.3.2) - 0 notes
  • 1.0.0 (0)
  • 1.1.6 (0)
  • 1.2.6 (4)
  • 2.0.3
  • 2.1.0
  • 2.2.1
  • 2.3.8
  • 3.0.0
  • 3.0.9
  • 3.1.0
  • 3.2.1
  • 3.2.8
  • 3.2.13
  • 4.0.2
  • 4.1.8
  • 4.2.1
  • 4.2.7
  • 4.2.9
  • 5.0.0.1
  • 5.1.7
  • 5.2.3
  • 6.0.0
  • 6.1.3.1
  • 6.1.7.7
  • 7.0.0
  • 7.1.3.2
  • 7.1.3.4
  • What's this?

Module deprecated or moved

This module is deprecated or moved on the latest stable version. The last existing version (v1.2.6) is shown here.

Action Pack pagination for Active Record collections

DEPRECATION WARNING: Pagination will be moved to a plugin in Rails 2.0. Install the classic_pagination plugin for forward compatibility:

  script/plugin install svn://errtheblog.com/svn/plugins/classic_pagination

The Pagination module aids in the process of paging large collections of Active Record objects. It offers macro-style automatic fetching of your model for multiple views, or explicit fetching for single actions. And if the magic isn’t flexible enough for your needs, you can create your own paginators with a minimal amount of code.

The Pagination module can handle as much or as little as you wish. In the controller, have it automatically query your model for pagination; or, if you prefer, create Paginator objects yourself.

Pagination is included automatically for all controllers.

For help rendering pagination links, see ActionView::Helpers::PaginationHelper.

Automatic pagination for every action in a controller

  class PersonController < ApplicationController
    model :person

    paginate :people, :order => 'last_name, first_name',
             :per_page => 20

    # ...
  end

Each action in this controller now has access to a @people instance variable, which is an ordered collection of model objects for the current page (at most 20, sorted by last name and first name), and a @person_pages Paginator instance. The current page is determined by the params[:page] variable.

Pagination for a single action

  def list
    @person_pages, @people =
      paginate :people, :order => 'last_name, first_name'
  end

Like the previous example, but explicitly creates @person_pages and @people for a single action, and uses the default of 10 items per page.

Custom/"classic" pagination

  def list
    @person_pages = Paginator.new self, Person.count, 10, params[:page]
    @people = Person.find :all, :order => 'last_name, first_name',
                          :limit  =>  @person_pages.items_per_page,
                          :offset =>  @person_pages.current.offset
  end

Explicitly creates the paginator from the previous example and uses Paginator#to_sql to retrieve @people from the model.

Constants

OPTIONS = Hash.new

DEFAULT_OPTIONS = { :class_name => nil, :singular_name => nil, :per_page => 10, :conditions => nil, :order_by => nil, :order => nil, :join => nil, :joins => nil, :count => nil, :include => nil, :select => nil, :parameter => 'page'

Attributes

Show files where this module is defined (1 file)
Register or log in to add new notes.