Class ActionController::Pagination::Paginator::Window
In: vendor/rails/actionpack/lib/action_controller/pagination.rb
Parent: Object

A class for representing ranges around a given page.

Methods

new   padding=   pages   to_a  

Attributes

first  [R] 
last  [R] 
padding  [R] 
page  [R] 
paginator  [R] 

Public Class methods

Creates a new Window object for the given page with the specified padding.

[Source]

     # File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 380
380:         def initialize(page, padding=2)
381:           @paginator = page.paginator
382:           @page = page
383:           self.padding = padding
384:         end

Public Instance methods

Sets the window‘s padding (the number of pages on either side of the window page).

[Source]

     # File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 389
389:         def padding=(padding)
390:           @padding = padding < 0 ? 0 : padding
391:           # Find the beginning and end pages of the window
392:           @first = @paginator.has_page_number?(@page.number - @padding) ?
393:             @paginator[@page.number - @padding] : @paginator.first
394:           @last =  @paginator.has_page_number?(@page.number + @padding) ?
395:             @paginator[@page.number + @padding] : @paginator.last
396:         end

Returns an array of Page objects in the current window.

[Source]

     # File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 400
400:         def pages
401:           (@first.number..@last.number).to_a.collect! {|n| @paginator[n]}
402:         end
to_a()

Alias for pages

[Validate]