Question

I generally do something like this, but if feels nasty and not very dry:

-if minutes == 1
  added #{minutes} minute ago
-else
  added #{minutes} minutes ago
Was it helpful?

Solution

See http://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html#method-i-pluralize

"added #{ pluralize(minutes, "minute") } ago"

There is an optional third argument that you can add if the plural version is non-standard and rails can't figure it out. For example (from the docs):

pluralize(3, 'person', 'users')

OTHER TIPS

<%= pluralize(minutes, "minute") %> if you're in a view.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top