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.
number | -> | to_i |
number | [R] | |
paginator | [R] |
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.
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 290 290: def initialize(paginator, number) 291: @paginator = paginator 292: @number = number.to_i 293: @number = 1 unless @paginator.has_page_number? @number 294: end
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.
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 311 311: def <=>(page) 312: raise ArgumentError unless @paginator == page.paginator 313: @number <=> page.number 314: 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).
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 301 301: def ==(page) 302: return false if page.nil? 303: @paginator == page.paginator and 304: @number == page.number 305: end
Returns true if this page is the first page in the paginator.
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 332 332: def first? 333: self == @paginator.first 334: end
Returns the number of the first item displayed.
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 322 322: def first_item 323: offset + 1 324: end
Returns true if this page is the last page in the paginator.
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 337 337: def last? 338: self == @paginator.last 339: end
Returns the number of the last item displayed.
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 327 327: def last_item 328: [@paginator.items_per_page * @number, @paginator.item_count].min 329: end
Returns the limit/offset array for this page.
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 360 360: def to_sql 361: [@paginator.items_per_page, offset] 362: end