Class: Commontator::Collection
- Inherits:
-
WillPaginate::Collection
- Object
- WillPaginate::Collection
- Commontator::Collection
- Defined in:
- app/models/commontator/collection.rb
Instance Attribute Summary collapse
-
#root_per_page ⇒ Object
readonly
Returns the value of attribute root_per_page.
Instance Method Summary collapse
-
#initialize(array, count, root_per_page, per_page, page = 1) ⇒ Collection
constructor
A new instance of Collection.
-
#page_zero? ⇒ Boolean
This method determines if we are in a shorter version of the first page, which we call page 0.
-
#total_pages ⇒ Object
We return 2 total_pages under certain conditions to trick will_paginate into rendering the pagination controls when it otherwise wouldn’t.
Constructor Details
#initialize(array, count, root_per_page, per_page, page = 1) ⇒ Collection
Returns a new instance of Collection.
9 10 11 12 13 14 15 16 17 |
# File 'app/models/commontator/collection.rb', line 9 def initialize(array, count, root_per_page, per_page, page = 1) self.total_entries = count @root_per_page = root_per_page @per_page = per_page @current_page = page_zero? ? 0 : WillPaginate::PageNumber(page) @first_call = true replace(array) end |
Instance Attribute Details
#root_per_page ⇒ Object (readonly)
Returns the value of attribute root_per_page.
2 3 4 |
# File 'app/models/commontator/collection.rb', line 2 def root_per_page @root_per_page end |
Instance Method Details
#page_zero? ⇒ Boolean
This method determines if we are in a shorter version of the first page, which we call page 0
5 6 7 |
# File 'app/models/commontator/collection.rb', line 5 def page_zero? total_entries > @per_page && @per_page < @root_per_page end |
#total_pages ⇒ Object
We return 2 total_pages under certain conditions to trick will_paginate into rendering the pagination controls when it otherwise wouldn’t
21 22 23 24 25 |
# File 'app/models/commontator/collection.rb', line 21 def total_pages min_total_pages = page_zero? && @first_call ? 2 : 1 @first_call = false [ (total_entries.to_f/@root_per_page).ceil, min_total_pages ].max end |