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
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
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
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 %{count}</b> %{model}"
multi_page: "Displaying %{model} %{from} - %{to} of %{count} in total"
multi_page_html: "Displaying %{model} <b>%{from} - %{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} - %{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.
© 2022 - 2024 — McMap. All rights reserved.