Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set :total_entries < 0 for uncounted paging. #250

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/will_paginate/collection.rb
100644 → 100755
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ module WillPaginate
# This module provides few of these methods. # This module provides few of these methods.
module CollectionMethods module CollectionMethods
def total_pages def total_pages
total_entries.zero? ? 1 : (total_entries / per_page.to_f).ceil return 1 if total_entries.zero?
return -1 if total_entries < 0
(total_entries / per_page.to_f).ceil
end end


# current_page - 1 or nil if there is no previous page # current_page - 1 or nil if there is no previous page
Expand All @@ -23,7 +25,7 @@ def previous_page


# current_page + 1 or nil if there is no next page # current_page + 1 or nil if there is no next page
def next_page def next_page
current_page < total_pages ? (current_page + 1) : nil ((current_page < total_pages) || (total_pages < 0)) ? (current_page + 1) : nil
end end


# Helper method that is true when someone tries to fetch a page with a # Helper method that is true when someone tries to fetch a page with a
Expand Down
5 changes: 4 additions & 1 deletion lib/will_paginate/view_helpers.rb
100644 → 100755
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -71,10 +71,13 @@ class << self
# #
def will_paginate(collection, options = {}) def will_paginate(collection, options = {})
# early exit if there is nothing to render # early exit if there is nothing to render
return nil unless collection.total_pages > 1 return nil if collection.total_pages == 0 ||
(collection.current_page == 1 && collection.length < collection.per_page)


options = WillPaginate::ViewHelpers.pagination_options.merge(options) options = WillPaginate::ViewHelpers.pagination_options.merge(options)


options[:page_links] = false if collection.total_pages < 0

options[:previous_label] ||= will_paginate_translate(:previous_label) { '&#8592; Previous' } options[:previous_label] ||= will_paginate_translate(:previous_label) { '&#8592; Previous' }
options[:next_label] ||= will_paginate_translate(:next_label) { 'Next &#8594;' } options[:next_label] ||= will_paginate_translate(:next_label) { 'Next &#8594;' }


Expand Down
4 changes: 3 additions & 1 deletion lib/will_paginate/view_helpers/link_renderer.rb
100644 → 100755
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ def previous_page
end end


def next_page def next_page
num = @collection.current_page < @collection.total_pages && @collection.current_page + 1 num = ((@collection.current_page < @collection.total_pages) ||
(@collection.total_pages < 0 && @collection.length >= @collection.per_page)) &&
@collection.current_page + 1
previous_or_next_page(num, @options[:next_label], 'next_page') previous_or_next_page(num, @options[:next_label], 'next_page')
end end


Expand Down