5

I have a question about the pluralize function. In my view, I have the following line of code. It passes in an item with a certain number of votes to determine if it the word "Vote" should be pluralized.

 <%= pluralize(item.votes, 'Vote') %>

My issue is that my view passes out the word "Votes" followed by the certain number of votes (item.votes). I only want it to pass out the word "Votes". Ideas are much appreciated.

Frederick Cheung
  • 83,189
  • 8
  • 152
  • 174
Astephen2
  • 821
  • 4
  • 13
  • 20

3 Answers3

10

You can do simpler:

"Vote".pluralize(item.votes)
Nima Izadi
  • 996
  • 6
  • 18
3

You can do:

pluralize(items.votes, 'Vote').split(" ", 2)[1]

Hope that helps!

Jesse Pollak
  • 1,600
  • 1
  • 15
  • 20
2

You can create your own method in a helper

def pluralize_without_count(string, count)
    count == 1 ? string : string.pluralize
end

and use it in your view:

<%= pluralize_without_count('Vote', item.votes) %>
Baldrick
  • 23,882
  • 6
  • 74
  • 79
  • 2
    if you want to consider the case of having *0* votes, you might want to slightly change this helper to: `count == 1 ? string : string.pluralize` – pruett Apr 19 '12 at 03:05
  • 1
    Yes, this should be changed to be: count == 1 ? string : string.pluralize – Edward Anderson Dec 07 '12 at 14:58