_4bdja
Last Updated: February 25, 2016
·
6.35K
· jeroenr
Dsc 0061

Pluralize without the number

It might seem quite obvious, but it took me some time to find this. If you use the pluralize helper, it will always include the number, rather than just pluralizing the word:

pluralize(2, 'day') 
# => 2 days

Apparently, Rails monkey-patched the String class to include a pluralize function which doesn't include the number:

"day".pluralize(2) 
# => days

I find it quite useful if you want to style the number differently from the text in your views.

Happy coding!

Say Thanks
Respond

3 Responses
Add your response

3051
392321 692815809906 50504925 33878144 117300072 n

thanks for the tip!

over 1 year ago ·
8462
95f1706834cbebd1439b981527e094f2

awesome easy!

over 1 year ago ·
11989
C0f3c10c460bf6bd738fc1cac4ce566b

Awesome tip. I was just playing around with this and found that you don't need the number:

'day'.pluralize
=> 'days'

similarly:

'days'.singularize
=> 'day'

over 1 year ago ·