Forum: Ruby on Rails how to build a Time Trigger action?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Nanyang Z. (Guest)
on 2007-01-10 18:35
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?
Philip H. (Guest)
on 2007-01-10 20:22
(Received via mailing list)
> 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
Nanyang Z. (Guest)
on 2007-01-11 12:06
thanks! philip
This topic is locked and can not be replied to.