A class representing a paginator for an Active Record collection.
- []
- current
- current_page
- current_page=
- each
- first
- first_page
- has_page_number?
- last
- last_page
- length
- new
- page_count
Class ActionController::Pagination::Paginator::Window
[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.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 215 215: def initialize(controller, item_count, items_per_page, current_page=1) 216: raise ArgumentError, 'must have at least one item per page' if 217: items_per_page <= 0 218: 219: @controller = controller 220: @item_count = item_count || 0 221: @items_per_page = items_per_page 222: @pages = {} 223: 224: self.current_page = current_page 225: end
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 273 273: def [](number) 274: @pages[number] ||= Page.new(self, number) 275: end
Alias for current_page
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 241 241: def current_page 242: @current_page ||= self[@current_page_number] 243: 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.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 231 231: def current_page=(page) 232: if page.is_a? Page 233: raise ArgumentError, 'Page/Paginator mismatch' unless 234: page.paginator == self 235: end 236: page = page.to_i 237: @current_page_number = has_page_number?(page) ? page : 1 238: end
Successively yields all the paginator‘s pages to the given block.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 278 278: def each(&block) 279: page_count.times do |n| 280: yield self[n+1] 281: end 282: end
Alias for first_page
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 247 247: def first_page 248: @first_page ||= self[1] 249: end
Returns true if this paginator contains the page of index number.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 267 267: def has_page_number?(number) 268: number >= 1 and number <= page_count 269: end
Alias for last_page
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 253 253: def last_page 254: @last_page ||= self[page_count] 255: end
Alias for page_count
Returns the number of pages in this paginator.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 259 259: def page_count 260: @page_count ||= @item_count.zero? ? 1 : 261: (q,r=@item_count.divmod(@items_per_page); r==0? q : q+1) 262: end