GVS GVS - 2 months ago 10
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

Try

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

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

Comments