Refresh string as plural if it is greater than 1

I have the following range, I want to use the pluralize method until there are 1 elements, I want to display 1 element, at the moment it has 0 elements by default. If something is added, it says 1 element

<span id="cartitems">
<%=@size%>
items
</span>
+4
source share
3 answers

Please use Rails I18n and write something like:

I18n.t('items', count: @size)

and then in the file config/locales/en.yml:

en:
  items:
    zero: "no items"
    one: "one item"
    other: "%{count} items"
+7
source

Do it instead

<%= pluralize(@size, 'item') %>

Hope this helps!

+6
source

How about using pluralize

<%= pluralize @size, 'item' %>
+2
source

All Articles