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.
C91098dc76d7ad473165ef24fe805312?d=identicon&s=25 Nanyang Zhan (xain)
on 2007-01-10 17: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?
2f9a03aa0fcfe945229cb6126eda2cb2?d=identicon&s=25 Philip Hallstrom (Guest)
on 2007-01-10 19: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
C91098dc76d7ad473165ef24fe805312?d=identicon&s=25 Nanyang Zhan (xain)
on 2007-01-11 11:06
thanks! philip
This topic is locked and can not be replied to.