Module: WillPaginate::CollectionMethods
- Included in:
- ActiveRecord::RelationMethods, Collection, SequelMethods
- Defined in:
- lib/will_paginate/collection.rb
Overview
Any will_paginate-compatible collection should have these methods:
current_page, per_page, offset, total_entries, total_pages
It can also define some of these optional methods:
out_of_bounds?, previous_page, next_page
This module provides few of these methods.
Instance Method Summary collapse
-
#next_page ⇒ Object
current_page + 1 or nil if there is no next page.
-
#out_of_bounds? ⇒ Boolean
Helper method that is true when someone tries to fetch a page with a larger number than the last page.
-
#previous_page ⇒ Object
current_page - 1 or nil if there is no previous page.
- #total_pages ⇒ Object
Instance Method Details
#next_page ⇒ Object
current_page + 1 or nil if there is no next page
25 26 27 |
# File 'lib/will_paginate/collection.rb', line 25 def next_page current_page < total_pages ? (current_page + 1) : nil end |
#out_of_bounds? ⇒ Boolean
Helper method that is true when someone tries to fetch a page with a larger number than the last page. Can be used in combination with flashes and redirecting.
32 33 34 |
# File 'lib/will_paginate/collection.rb', line 32 def out_of_bounds? current_page > total_pages end |
#previous_page ⇒ Object
current_page - 1 or nil if there is no previous page
20 21 22 |
# File 'lib/will_paginate/collection.rb', line 20 def previous_page current_page > 1 ? (current_page - 1) : nil end |
#total_pages ⇒ Object
15 16 17 |
# File 'lib/will_paginate/collection.rb', line 15 def total_pages total_entries.zero? ? 1 : (total_entries / per_page.to_f).ceil end |