Wednesday, February 10, 2010

pluralize helper method in rails

Syntax:

pluralize(count, singular, plural = nil)

How to user use

pluralize(1, 'person')         # => 1 person
pluralize(2, 'person')        # => 2 people

pluralize(3, 'person', 'users')    # => 3 users
pluralize(0, 'person')       # => 0 people

Calculating the Number of Days Between Two Dates in ruby on rails



def room_expiry_date_in_days(room)
a=room.expiry_date.strftime("%Y-%m-%d")
b=room.created_at.strftime("%Y-%m-%d")
a=Date.parse(a)
b=Date.parse(b)
days=(a-b).to_i
return  "#{pluralize(days, 'day',"days")} left"
end