Вопрос

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
Это было полезно?

Решение

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')

Другие советы

<%= pluralize(minutes, "minute") %> if you're in a view.
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top