| Class | ActionController::Pagination::Paginator |
| In: |
vendor/rails/actionpack/lib/action_controller/pagination.rb
|
| Parent: | Object |
A class representing a paginator for an Active Record collection.
| controller | [R] | |
| item_count | [R] | |
| items_per_page | [R] |
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 214
214: def initialize(controller, item_count, items_per_page, current_page=1)
215: raise ArgumentError, 'must have at least one item per page' if
216: items_per_page <= 0
217:
218: @controller = controller
219: @item_count = item_count || 0
220: @items_per_page = items_per_page
221: @pages = {}
222:
223: self.current_page = current_page
224: end
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 230
230: def current_page=(page)
231: if page.is_a? Page
232: raise ArgumentError, 'Page/Paginator mismatch' unless
233: page.paginator == self
234: end
235: page = page.to_i
236: @current_page_number = has_page_number?(page) ? page : 1
237: end
Successively yields all the paginator‘s pages to the given block.
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 277
277: def each(&block)
278: page_count.times do |n|
279: yield self[n+1]
280: end
281: end
Returns true if this paginator contains the page of index number.
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 266
266: def has_page_number?(number)
267: number >= 1 and number <= page_count
268: end