ruby - I need to display results from time_ago_in_words as "days ago" only -
when pass rails time_ago_in_words method date greater 1 month ago, returns string reads "about n months old".
is there anyway have method return distance date paramater in days i.e. 30 days ago, 50 days ago, 90 days ago etc...
class time def days_ago diff = time.now - self return ago if diff < 86400 "#{"day".pluralize(diff.to_i / 86400)} ago" end end class date def days_ago to_time.days_ago end end or helper:
def days_ago(date) diff = time.now - date.to_time return date.ago if diff < 86400 "#{"day".pluralize(diff.to_i / 86400)} ago" end
Comments
Post a Comment