A class representing a paginator for an Active Record collection.
- CLASS ActionController::Pagination::Paginator::Page
 - CLASS ActionController::Pagination::Paginator::Window
 
- #
 - C
 - E
 - F
 - H
 - L
 - N
 - P
 
| [R] | controller | |
| [R] | item_count | |
| [R] | items_per_page | 
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.
Source: show
# File rails/actionpack/lib/action_controller/pagination.rb, line 221 def initialize(controller, item_count, items_per_page, current_page=1) raise ArgumentError, 'must have at least one item per page' if items_per_page <= 0 @controller = controller @item_count = item_count || 0 @items_per_page = items_per_page @pages = {} self.current_page = current_page end
Returns a new Page representing the page
with the given index number.
Source: show
# File rails/actionpack/lib/action_controller/pagination.rb, line 279 def [](number) @pages[number] ||= Page.new(self, number) end
Returns a Page object representing this paginator’s current page.
Source: show
# File rails/actionpack/lib/action_controller/pagination.rb, line 247 def current_page @current_page ||= self[@current_page_number] 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.
Source: show
# File rails/actionpack/lib/action_controller/pagination.rb, line 237 def current_page=(page) if page.is_a? Page raise ArgumentError, 'Page/Paginator mismatch' unless page.paginator == self end page = page.to_i @current_page_number = has_page_number?(page) ? page : 1 end
Successively yields all the paginator’s pages to the given block.
Source: show
# File rails/actionpack/lib/action_controller/pagination.rb, line 284 def each(&block) page_count.times do |n| yield self[n+1] end end
Returns a new Page representing the first page in this paginator.
Source: show
# File rails/actionpack/lib/action_controller/pagination.rb, line 253 def first_page @first_page ||= self[1] end
Returns true if this paginator contains the page of index
number.
Source: show
# File rails/actionpack/lib/action_controller/pagination.rb, line 273 def has_page_number?(number) number >= 1 and number <= page_count end