0

I was wondering what would be the best solution for customising the rails helper: time_ago_in_words, so that I could do things like:

    <span class="one">4</span>
    <span class="two">hours</span>
    <span class="three">ago</span>

or what the layout looks like by default?

Thanks

Darcbar
  • 888
  • 1
  • 8
  • 25

2 Answers2

1

I would just create a helper that splits the result of time_ago_in_words on spaces and returns the array of words. Then you can format them however you want.

Nick
  • 2,418
  • 16
  • 20
  • That's a good idea, I just wonder if I might need something even more customizable as I want to remove the 'about' and also display a date (21 Jan 2011) after a year has passed instead of 'about one year ago', but I will accept your answer in relevance to the question. thanks – Darcbar Jan 26 '12 at 14:47
0

Instead of the method time_ago_in_words, you can use distance_of_time_in_words, which accepts locale in the option array: create a new locale where you can define "hours" with "hours", etc... and give it to distance_of_time_in_words. It should work, but I'm not sure how will be handled the HTML tags.

Baldrick
  • 23,882
  • 6
  • 74
  • 79