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

2

2

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?

Ballman answered 4/10, 2011 at 20:30 Comment(0)
L
3

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
Lamoreaux answered 5/10, 2011 at 17:39 Comment(0)
B
2

Use the :entry_name parameter.

= page_entries_info @posts, :entry_name => 'item'
#-> Displaying items 6 - 10 of 26 in total
Ballman answered 5/10, 2011 at 17:34 Comment(1)
This is now :model, e.g. model: 'item'Befriend

© 2022 - 2024 — McMap. All rights reserved.