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!
Written by Jeroen Rosenberg
Related protips
3 Responses
thanks for the tip!
over 1 year ago
·
awesome easy!
over 1 year ago
·
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
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#