# Question on implementing \<r:time\_ago\_in\_words/\> and Radiant

**URL:** <https://www.ruby-forum.com/t/question-on-implementing-r-time-ago-in-words-and-radiant/67765>\
**Category:** Radiant CMS\
**Created:** [September 6, 2006, 5:26pm UTC](https://www.ruby-forum.com/t/question-on-implementing-r-time-ago-in-words-and-radiant/67765 "2006-09-06T17:26:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![df-sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@df-sean](https://www.ruby-forum.com/u/df-sean)\
**Post date:** [September 6, 2006, 5:26pm UTC](https://www.ruby-forum.com/t/question-on-implementing-r-time-ago-in-words-and-radiant/67765/1 "2006-09-06T17:26:18Z")

</div>

I’d like to implement a time\_ago\_in\_words tag so that I could write

```
<p">Posted by <r:author /> <r:time_ago_in_words /> ago</p>

```

and get

```
<p>Posted by Sean 5 days ago</p>

```

I figured since Rails already has a time\_ago\_in\_words helper, I’d  
just reuse it. But is the following a reasonable implementation? Does  
it conform at all with “the Radiant way” of doing things?

# this require bit feels a bit awkward

require ‘…/…/vendor/rails/actionpack/lib/action\_view/helpers/  
date\_helper’

# and so does this include

class Behavior::Base  
include ActionView::Helpers::DateHelper  
end

class CantThinkOfAGoodNameForThisBehavior \< Behavior::Base

register “Cant Think of a Good Name for This”

description %{  
Adds a global time\_ago\_in\_words tag, as often seen in blog  
entries (“Posted by Jack 3 days ago”)  
}

# I want to use this tag anywhere soI’m using Base.define\_tags,

# but since I registered above, it’ll appear in the Behaviors drop

down,

# which doesn’t seem cool . . .

Behavior::Base.define\_tags do

```
 tag "time_ago_in_words" do |tag|
   date = tag.locals.page.published_at || tag.locals.page.created_at
   time_ago_in_words date
 end

```

end

end

---

<div class="post-metadata">

**Author:** ![df-sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@df-sean](https://www.ruby-forum.com/u/df-sean)\
**Post date:** [September 6, 2006, 5:34pm UTC](https://www.ruby-forum.com/t/question-on-implementing-r-time-ago-in-words-and-radiant/67765/2 "2006-09-06T17:34:23Z")

</div>

Sean, try this.

class Behavior::Base  
define\_tags do  
tag “time\_ago\_in\_words” do |tag|  
ActionView::Base.new.time\_ago\_in\_words(tags.locals.page.created\_at)  
end  
end  
end

You could substitute published\_at for created\_at in that statement.

Cheers,

Sean C.  
[seancribbs.com](http://seancribbs.com)

---

<div class="post-metadata">

**Author:** ![df-sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@df-sean](https://www.ruby-forum.com/u/df-sean)\
**Post date:** [September 7, 2006, 4:43am UTC](https://www.ruby-forum.com/t/question-on-implementing-r-time-ago-in-words-and-radiant/67765/3 "2006-09-07T04:43:36Z")

</div>

On Sep 7, 2006, at 12:33 AM, Sean C. wrote:

> 

Remember that Radiant caching will give you some problems with  
this… but seeing as the cache expires after 5 minutes, i don’t  
think it will be much of an issue.

Bodhi
