Post Image
By Matt GaidicaJune 8, 2012In Uncategorized

A Better time_ago_in_words for Ruby on Rails

def time_ago time, append = ' ago'
  return time_ago_in_words(time).gsub(/about|less than|almost|over/, '').strip << append

I love the time_ago_in_words method that comes bundled with rails, but it often produces a pretty lengthy string that doesn’t fit on narrow columns, or mobile views. This is a simple fix I use, placed in “helpers/application_helper.rb”.

#a minute ago

#5 minutes ago

time_ago( - 20.years, '!')
#20 years!
svgMaking files public in Amazon S3 and the owner problem
svgrspec_helper.rb for Rspec in Ruby