How do I specify custom wording in a will_paginate view helper?

試著忘記壹切 提交于 2019-12-24 03:19:05

问题


I'm using will_paginate 2.3.25 with Rails 2.3.11.

I'd like my page_entries_info view helper to say "Displaying all n [my own custom wording]s" instead of auto-generating the item name based on the model.

What is the syntax to make it do that?


回答1:


Set up your translation yaml file to include what you want to call that model when it is being paginated.

After reading this documentation: https://github.com/mislav/will_paginate/wiki/I18n

en:
  will_paginate:
    models:
      line_item:
        zero:  line items
        one:   line item
        few:   line items
        other: line items

Or for a "just this once solution" you can use page_entries_info

From the RDoc:

page_entries_info(collection, options = {})

Renders a helpful message with numbers of displayed vs. total entries. You can use this as a blueprint for your own, similar helpers.

  <%= page_entries_info @posts %>
  #-> Displaying posts 6 - 10 of 26 in total

By default, the message will use the humanized class name of objects in collection: for instance, "project types" for ProjectType models. Override this with the :entry_name parameter:

  <%= page_entries_info @posts, :entry_name => 'item' %>
  #-> Displaying items 6 - 10 of 26 in total



回答2:


Use the :entry_name parameter.

= page_entries_info @posts, :entry_name => 'item'
#-> Displaying items 6 - 10 of 26 in total


来源:https://stackoverflow.com/questions/7653669/how-do-i-specify-custom-wording-in-a-will-paginate-view-helper

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!