Fix bug where models weren't being pluralized correctly in page_entries_info #208

Closed
wants to merge 2 commits into
from
View
2 lib/will_paginate/active_record.rb
@@ -65,7 +65,7 @@ def count
rel = self.except(*excluded)
# TODO: hack. decide whether to keep
rel = rel.apply_finder_options(@wp_count_options) if defined? @wp_count_options
- rel.count
+ rel.to_sql =~ /DISTINCT .*ON/i ? rel.length : rel.count
else
super
end
View
5 lib/will_paginate/view_helpers.rb
@@ -132,12 +132,13 @@ def page_entries_info(collection, options = {})
end
}
model_name = will_paginate_translate defaults, :count => model_count
-
+ model_name = model_name.pluralize if collection.size > 1
+
if collection.total_pages < 2
i18n_key = :"page_entries_info.single_page#{html_key}"
keys = [:"#{model_key}.#{i18n_key}", i18n_key]
- will_paginate_translate keys, :count => collection.size, :model => model_name do |_, opts|
+ will_paginate_translate keys, :count => collection.length, :model => model_name do |_, opts|
case opts[:count]
when 0; "No #{opts[:model]} found"
when 1; "Displaying #{b}1#{eb} #{opts[:model]}"