Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pluralize in Rails View Issues

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.

like image 493
Astephen2 Avatar asked Jan 14 '12 18:01

Astephen2


3 Answers

You can do simpler:

"Vote".pluralize(item.votes)
like image 135
Nima Izadi Avatar answered Nov 10 '22 13:11

Nima Izadi


You can do:

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

Hope that helps!

like image 33
Jesse Pollak Avatar answered Nov 10 '22 15:11

Jesse Pollak


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) %>
like image 2
Baldrick Avatar answered Nov 10 '22 14:11

Baldrick