在rails中的will_paginate的page_entries_info中提供自定义消息

我是铁杆新手。 我想为page_entries_info显示我的自定义消息。 我已经通过以下链接但不能理解。 任何人都可以详细解释。

怎么办-I-指定定制-措辞-IN-A-意志PAGINATE视辅助

另一个选择是您可以在ApplicationHelper定义page_entries_info()方法并像往常一样使用它。 如果您知道不需要覆盖边缘情况(如我的情况),这将为您提供更大的灵活性,甚至可以更加清洁和高效。 您可以在此处参考原始方法定义,并查看您需要实现的所有内容。 以下代码将运行您的大部分问题!

 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 

这是默认加载的,取自项目维基

 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 1 %{model}" other: "Displaying all %{count} %{model}" multi_page: "Displaying %{model} %{from} - %{to} of %{count} in total" multi_page_html: "Displaying %{model} %{from} - %{to} of %{count} in total" 

你需要更改multi_page_htmlmulti_page ,最后2个条目。

在你的en.yml文件(或其他任何东西)中放置如下内容:

 en: will_paginate: line_item: page_entries_info: multi_page: "Displaying %{from} - %{to} of %{count} of %{model}" multi_page_html: "Displaying %{from} - %{to} of %{count} of %{model}" 

如果你有关于yml文件rails的困难, i18n指南有点高级,但提供了有关如何使用yml文件的很好的信息 – 只需向下滚动一点:)。

我希望它有所帮助。