7

I am new to rails. I want to display my custom message for page_entries_info. I have gone through following link but cannot understand much. Can anyone please explain in details.

how-do-i-specify-custom-wording-in-a-will-paginate-view-helper

Community
  • 1
  • 1
Paritosh Singh
  • 6,288
  • 5
  • 37
  • 56
  • what exactly you want to customize? can you explain a little more? – Alper Karapınar Aug 01 '12 at 11:13
  • actually for me default message coming is "Displaying Topic 1 - 5 of 57 in total", i want to make it as "Displaying 1 - 5 of 57 of Topic". I've gone through the link but can't understand where to add Yaml file. How it works? – Paritosh Singh Aug 01 '12 at 11:20

2 Answers2

9

Another option is you can define your page_entries_info() method in your ApplicationHelper and use it as you normally would. This would give you more flexibility and can even be more cleaner and efficient if you know that you dont need to cover the edge cases (as in my case). You can refer the original method definition here and see what all you need to implement. Following code would run for most part of your problem!

def page_entries_info(collection, options = {})
  entry_name = options[:entry_name] || (collection.empty?? 'item' :
      collection.first.class.name.split('::').last.titleize)
  if collection.total_pages < 2
    case collection.size
    when 0; "No #{entry_name.pluralize} found"
    else; "Displaying all #{entry_name.pluralize}"
    end
  else
    %{Displaying %d - %d of %d #{entry_name.pluralize}} % [
      collection.offset + 1,
      collection.offset + collection.length,
      collection.total_entries
    ]
  end
end
atmaish
  • 2,495
  • 3
  • 22
  • 25
8

This is what is loaded by default, taken from project wiki

en:
  will_paginate:
    page_entries_info:
      single_page:
        zero:  "No %{model} found"
        one:   "Displaying 1 %{model}"
        other: "Displaying all %{count} %{model}"
      single_page_html:
        zero:  "No %{model} found"
        one:   "Displaying <b>1</b> %{model}"
        other: "Displaying <b>all&nbsp;%{count}</b> %{model}"

      multi_page: "Displaying %{model} %{from} - %{to} of %{count} in total"
      multi_page_html: "Displaying %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b> of <b>%{count}</b> in total"

you need to change multi_page_html and multi_page, the last 2 entries.

in your en.yml file (or whatever it is) put something like this:

en:
  will_paginate:
    line_item:
      page_entries_info:
        multi_page: "Displaying %{from} - %{to} of %{count} of %{model}"        
        multi_page_html: "Displaying <b>%{from}&nbsp;-&nbsp;%{to}</b> of <b>%{count}</b> of %{model}"

If you have difficulties about yml file rails i18n guide is a little advanced but gives nice information about how to use yml file - just scroll down a little :).

I hope it helps.

Alper Karapınar
  • 2,694
  • 1
  • 25
  • 36