Hi Stephan,

I am not too sure where exactly you are trying to execute this time 
based procedure. It can be done on several different levels, each of 
which would result in a different solution.

However, from the following statement I will assume that you might be 
wanting to perform some duties on the model level:

"I want a countdown which is counting autonomus and starts if the user
logged in."

Say that you are simply wanting to save an active record object every 5 
minutes after the user has logged in.  If the lifespan of an active 
record object will be persistent throughout a user's session, which I 
would NOT advise, there is a really neat gem called the rufus scheduler 
that might do the trick.

http://rufus.rubyforge.org/rufus-scheduler/

You could use it in your model like so:

class Fish < ActiveRecord::Base
    require 'rubygems'
    require 'rufus/scheduler'

    SCHEDULER = Rufus::Scheduler.start_new

    def initialize
        super

        SCHEDULER.every "5m" do
           #might want to consider the fact that this object could be in 
a state where it can't save due to validation constraints
           self.save
        end
    end
end

Otherwise, you could simply check the "updated_at" timestamp for the 
active record in the controller and run some code every 5 minutes 
(current_time - updated_at > 5 minutes). Of course the drawback here is 
that it is completely contingent upon the user making requests to the 
server.

HTH,
Aldo Sarmiento
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to