GVS GVS - 1 year ago 79
Ruby Question

How to pluralize this sentence?

I am trying to display the number of followers a user has.

My original code was

<h5><%= current_user.followers.count %> followers<h5>

This produces the incorrect statement: "1 followers"

How to pluralize this sentence? I experimented with the following and I can't get it to work.

<%= 'follower'.pluralize(current_user.followers.count) %>

This displays just the word "follower" and no number in front of it.

Answer Source


<%= pluralize(current_user.followers.count, 'follower') %>

See http://apidock.com/rails/ActionView/Helpers/TextHelper/pluralize

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download