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