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
- Enumerable
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 192
192: def initialize(controller, item_count, items_per_page, current_page=1)
193: raise ArgumentError, 'must have at least one item per page' if
194: items_per_page <= 0
195:
196: @controller = controller
197: @item_count = item_count || 0
198: @items_per_page = items_per_page
199:
200: self.current_page = current_page
201: end
Returns a new Page representing the page with the given index number.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 249
249: def [](number)
250: Page.new(self, number)
251: end
Alias for current_page
Returns a Page object representing this paginator’s current page.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 217
217: def current_page
218: self[@current_page]
219: 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 207
207: def current_page=(page)
208: if page.is_a? Page
209: raise ArgumentError, 'Page/Paginator mismatch' unless
210: page.paginator == self
211: end
212: page = page.to_i
213: @current_page = has_page_number?(page) ? page : 1
214: end
Successively yields all the paginator’s pages to the given block.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 254
254: def each(&block)
255: page_count.times do |n|
256: yield self[n+1]
257: end
258: end
Alias for first_page
Returns a new Page representing the first page in this paginator.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 223
223: def first_page
224: self[1]
225: end
Returns true if this paginator contains the page of index number.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 242
242: def has_page_number?(number)
243: return false unless number.is_a? Fixnum
244: number >= 1 and number <= page_count
245: end
Alias for last_page
Returns a new Page representing the last page in this paginator.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 229
229: def last_page
230: self[page_count]
231: 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 235
235: def page_count
236: return 1 if @item_count.zero?
237: (@item_count / @items_per_page.to_f).ceil
238: end