How can I get will_paginate to correctly display the number of records?

WillPaginate has a helper helper page_entries_info for outputting text like "Display contracts 1 - 35 of 4825 as a whole."

However, I find it when I try to use it like this ...

 = page_entries_info @contracts 

He infers ...

Display contract 1 - 35 of 4825 in total

(It prints a single model name, not a plural, all in lower case.)

Do I need to pass some other parameter?

I tried page_entries_info @contracts, :model => Contract , but got the same result.

I am using version 3.0.3 - the current version.

By the way, can someone point me to the API docs for WillPaginate?

+4
source share
1 answer

will_paginate API docs: https://github.com/mislav/will_paginate/wiki/API-documentation

Short answer

You can specify the model parameter as a string that will be correctly pluralized.

 page_entries_info @contracts, :model => 'contract' # Displaying contracts 1 - 35 of 4825 in total 

Longer answer

will_paginate docs suggests that you use the i18n engine to configure output. It's kind of a pain from AFAICT, you have to write out a single and multiple form for all your models in config/locales/*.yml (for example, en.yml), and the syntax %{foo} not like ERB, but just placeholders, therefore, you cannot do things like %{foo.downcase} .

If you write your assistant, you get full control over the exit. For instance:

 def my_page_info(collection) model_class = collection.first.class if model_class.respond_to? :model_name model = model_class.model_name.human.downcase models = model.pluralize if collection.total_entries == 0 "No #{models} found." elsif collection.total_entries == 1 "Found one #{model}." elsif collection.total_pages == 1 "Displaying all #{collection.total_entries} #{models}" else "Displaying #{models} #{collection.offset + 1} " + "to #{collection.offset + collection.length} " + "of #{number_with_delimiter collection.total_entries} in total" end end end # Displaying contracts 1 - 35 of 4,825 in total 
+2
source

All Articles