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

A class representing a single page in a paginator.

Methods

<=>   ==   first?   first_item   last?   last_item   new   next   offset   previous   to_sql   window  

Included Modules

Comparable

External Aliases

number -> to_i

Attributes

number  [R] 
paginator  [R] 

Public Class methods

Creates a new Page for the given paginator with the index number. If number is not in the range of valid page numbers or is not a number at all, it defaults to 1.

[Source]

     # File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 267
267:         def initialize(paginator, number)
268:           @paginator = paginator
269:           @number = number.to_i
270:           @number = 1 unless @paginator.has_page_number? @number
271:         end

Public Instance methods

Compares two Page objects and returns -1 if the left-hand page comes before the right-hand page, 0 if the pages are equal, and 1 if the left-hand page comes after the right-hand page. Raises ArgumentError if the pages do not belong to the same Paginator object.

[Source]

     # File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 288
288:         def <=>(page)
289:           raise ArgumentError unless @paginator == page.paginator
290:           @number <=> page.number
291:         end

Compares two Page objects and returns true when they represent the same page (i.e., their paginators are the same and they have the same page number).

[Source]

     # File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 278
278:         def ==(page)
279:           return false if page.nil?
280:           @paginator == page.paginator and 
281:             @number == page.number
282:         end

Returns true if this page is the first page in the paginator.

[Source]

     # File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 309
309:         def first?
310:           self == @paginator.first
311:         end

Returns the number of the first item displayed.

[Source]

     # File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 299
299:         def first_item
300:           offset + 1
301:         end

Returns true if this page is the last page in the paginator.

[Source]

     # File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 314
314:         def last?
315:           self == @paginator.last
316:         end

Returns the number of the last item displayed.

[Source]

     # File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 304
304:         def last_item
305:           [@paginator.items_per_page * @number, @paginator.item_count].min
306:         end

Returns a new Page object representing the page just after this page, or nil if this is the last page.

[Source]

     # File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 326
326:         def next
327:           if last? then nil else Page.new(@paginator, @number + 1) end
328:         end

Returns the item offset for the first item in this page.

[Source]

     # File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 294
294:         def offset
295:           @paginator.items_per_page * (@number - 1)
296:         end

Returns a new Page object representing the page just before this page, or nil if this is the first page.

[Source]

     # File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 320
320:         def previous
321:           if first? then nil else Page.new(@paginator, @number - 1) end
322:         end

Returns the limit/offset array for this page.

[Source]

     # File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 337
337:         def to_sql
338:           [@paginator.items_per_page, offset]
339:         end

Returns a new Window object for this page with the specified padding.

[Source]

     # File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 332
332:         def window(padding=2)
333:           Window.new(self, padding)
334:         end

[Validate]