A class representing a paginator for an Active Record collection.

Methods
Included Modules
Classes and Modules
Class ActionController::Pagination::Paginator::Page
Class ActionController::Pagination::Paginator::Window
Attributes
[R] controller
[R] item_count
[R] items_per_page
Public Class methods
new(controller, item_count, items_per_page, current_page=1)

Creates a new Paginator on the given controller for a set of items of size item_count and having items_per_page items per page. Raises ArgumentError if items_per_page is out of bounds (i.e., less than or equal to zero). The page CGI parameter for links defaults to "page" and can be overridden with page_parameter.

     # File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 208
208:       def initialize(controller, item_count, items_per_page, current_page=1)
209:         raise ArgumentError, 'must have at least one item per page' if
210:           items_per_page <= 0
211: 
212:         @controller = controller
213:         @item_count = item_count || 0
214:         @items_per_page = items_per_page
215:         @pages = {}
216:         
217:         self.current_page = current_page
218:       end
Public Instance methods
[](number)

Returns a new Page representing the page with the given index number.

     # File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 266
266:       def [](number)
267:         @pages[number] ||= Page.new(self, number)
268:       end
current()

Alias for current_page

current_page()

Returns a Page object representing this paginator’s current page.

This method is also aliased as current
     # File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 234
234:       def current_page
235:         @current_page ||= self[@current_page_number]
236:       end
current_page=(page)

Sets the current page number of this paginator. If page is a Page object, its number attribute is used as the value; if the page does not belong to this Paginator, an ArgumentError is raised.

     # File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 224
224:       def current_page=(page)
225:         if page.is_a? Page
226:           raise ArgumentError, 'Page/Paginator mismatch' unless
227:             page.paginator == self
228:         end
229:         page = page.to_i
230:         @current_page_number = has_page_number?(page) ? page : 1
231:       end
each() {|self[n+1]| ...}

Successively yields all the paginator’s pages to the given block.

     # File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 271
271:       def each(&block)
272:         page_count.times do |n|
273:           yield self[n+1]
274:         end
275:       end
first()

Alias for first_page

first_page()

Returns a new Page representing the first page in this paginator.

This method is also aliased as first
     # File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 240
240:       def first_page
241:         @first_page ||= self[1]
242:       end
has_page_number?(number)

Returns true if this paginator contains the page of index number.

     # File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 260
260:       def has_page_number?(number)
261:         number >= 1 and number <= page_count
262:       end
last()

Alias for last_page

last_page()

Returns a new Page representing the last page in this paginator.

This method is also aliased as last
     # File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 246
246:       def last_page
247:         @last_page ||= self[page_count] 
248:       end
length()

Alias for page_count

page_count()

Returns the number of pages in this paginator.

This method is also aliased as length
     # File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 252
252:       def page_count
253:         @page_count ||= @item_count.zero? ? 1 :
254:                           (q,r=@item_count.divmod(@items_per_page); r==0? q : q+1)
255:       end