Topic: Simple but only marginally useful tip

Ever have problems when counting items and keeping track of the whether or not the word use should be plural?

For instance lets say you have some social networking site that notifies you if you have any messages, sometimes it will say something like "you have 1 messages waiting to be read." I really hate that.

Try adding this code to your one of your controller helpers.

  def make_plural(singular,plural,number)
    number != 1 ? plural : singular
  end

Pass it the singular form and plural forms of whatever it is you are counting, and the number of the items being counted. It will return the singular when there is one item, and plural in all other cases (remember that if there are zero items it should be plural).

Like I said, only marginally useful, but I had to post this since I always get irritated when a website gets this wrong.

Re: Simple but only marginally useful tip

Hi Dahuk,
Thanks for the tip. Rails does come with a built in helper method called "pluralize()" that is defined in TextHelper module.

http://www.noobkit.com/show/ruby/rails/ … alize.html

While we are on the topic of marginally useful, I'll add my marginally useful method too, "is_or_are()"!

# ApplicationHelper

  def is_or_are(quantity)
    quantity > 1 ? "are" : "is"
  end

# View
>> number=5;singular="finger"
=> "finger"
>> puts "There #{is_or_are(number)} #{pluralize(number, singular)} on my hand"
There are 5 fingers on my hand
=> nil