# How to build a Time Trigger action?

**URL:** <https://www.ruby-forum.com/t/how-to-build-a-time-trigger-action/81613>\
**Category:** Rails\
**Created:** [January 10, 2007, 5:35pm UTC](https://www.ruby-forum.com/t/how-to-build-a-time-trigger-action/81613 "2007-01-10T17:35:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![xain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/82dd89/32.png) [@xain](https://www.ruby-forum.com/u/xain)\
**Post date:** [January 10, 2007, 5:35pm UTC](https://www.ruby-forum.com/t/how-to-build-a-time-trigger-action/81613/1 "2007-01-10T17:35:45Z")

</div>

I use a week-hits attribute for my article model to count weekly page  
views.  
I want this attribute to be set to 0 on every sunday 0:00.  
How can I do that?

---

<div class="post-metadata">

**Author:** ![xain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/82dd89/32.png) [@xain](https://www.ruby-forum.com/u/xain)\
**Post date:** [January 10, 2007, 7:22pm UTC](https://www.ruby-forum.com/t/how-to-build-a-time-trigger-action/81613/2 "2007-01-10T19:22:06Z")

</div>

> I use a week-hits attribute for my article model to count weekly page  
> views.  
> I want this attribute to be set to 0 on every sunday 0:00.  
> How can I do that?

In your article model define a method something like this:

def self.zero\_week\_hits

# do whatever you need to do to zero them

end

Then via the command line you can run the following:

/path/to/rails\_root/script/runner Article.zero\_week\_hits -e production

Put that line into your cron file to run every sunday at 0:00.

-philip

---

<div class="post-metadata">

**Author:** ![xain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/82dd89/32.png) [@xain](https://www.ruby-forum.com/u/xain)\
**Post date:** [January 11, 2007, 11:06am UTC](https://www.ruby-forum.com/t/how-to-build-a-time-trigger-action/81613/3 "2007-01-11T11:06:19Z")

</div>

thanks! philip
