The Inflector module in Rails' Active Support library is responsible for the pluralize (as well as singularize, titleize, camelize, etc.) word fun that we all love. But, I often forget about the extra love provided by TextHelper module in ActiveView::Helpers.
I was just about to add a method to my application helper in a recent app that would allow me to pass a count value as well as a string value and get back either a plural or singular form of the word based on the count (using the respective inflector methods). As I started to type out the couple of lines to do this, the light bulb went on. Wait a minute I think Rails already does this for me. Sure enough, fire up the API and there it is in ActionView::Helpers::TextHelpers,
pluralize(count, singular, plural=nil)
In case you haven't looked at the TextHelper module API in a bit, don't forget all the fun stuff that you don't need to re-invent yourself, like: word_wrap, truncate, strip_tags, strip_links, sanitize, highlight, excerpt, etc.
No comments:
Post a Comment