Current page number
# File lib/kaminari/models/page_scope_methods.rb, line 37 def current_page offset_without_padding = offset_value offset_without_padding -= @_padding if defined?(@_padding) && @_padding offset_without_padding = 0 if offset_without_padding < 0 (offset_without_padding / limit_value) + 1 end
First page of the collection?
# File lib/kaminari/models/page_scope_methods.rb, line 56 def first_page? current_page == 1 end
Last page of the collection?
# File lib/kaminari/models/page_scope_methods.rb, line 61 def last_page? current_page >= total_pages end
Next page number in the collection
# File lib/kaminari/models/page_scope_methods.rb, line 46 def next_page current_page + 1 unless last_page? end
FIXME for compatibility. remove num_pages at some time in the future
Out of range of the collection?
# File lib/kaminari/models/page_scope_methods.rb, line 66 def out_of_range? current_page > total_pages end
# File lib/kaminari/models/page_scope_methods.rb, line 15 def padding(num) @_padding = num offset(offset_value + num.to_i) end
Specify the per_page value for the preceding page scope
Model.page(3).per(10)
# File lib/kaminari/models/page_scope_methods.rb, line 5 def per(num) if (n = num.to_i) <= 0 self elsif max_per_page && max_per_page < n limit(max_per_page).offset(offset_value / limit_value * max_per_page) else limit(n).offset(offset_value / limit_value * n) end end
Previous page number in the collection
# File lib/kaminari/models/page_scope_methods.rb, line 51 def prev_page current_page - 1 unless first_page? end
Total number of pages
# File lib/kaminari/models/page_scope_methods.rb, line 21 def total_pages count_without_padding = total_count count_without_padding -= @_padding if defined?(@_padding) && @_padding count_without_padding = 0 if count_without_padding < 0 total_pages_count = (count_without_padding.to_f / limit_value).ceil if max_pages.present? && max_pages < total_pages_count max_pages else total_pages_count end end
Generated with the Darkfish Rdoc Generator 2.