Forum: Ruby on Rails Web Page Timer

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.
A5d3e8b90c66904f218903b6a9f7b63e?d=identicon&s=25 dhashi (Guest)
on 2007-02-06 05:35
(Received via mailing list)
Greetings,

I was wondering if there was a way of making a timer or a timed
activity on a webpage.
The purpose is a timed exam or test which the candidate will submit
and be taken to another page
based on the result. If the exam isn't submitted on time - it needs to
end automatically.
Being new to Ruby or RoR itself - I was hoping someone could point me
in the right direction to solve this problem.

Thank you

Dhashi
Ef0db53920b243d6758c2f6b1306df0d?d=identicon&s=25 Steve Ross (cwd)
on 2007-02-06 08:00
(Received via mailing list)
This is done often on financial sites like banks and brokerages.
Basically,
you have to use two devices. The first is JavaScript on the client that
does
a redirect after time expires. Basically, you set a timer to the number
of
seconds the user has, then after that time expires, your JavaScript is
called. That JavaScript just does the redirect:

window.top.location.href = 'http://someplace.else.com'

That solves half the problem. The other half is if the client has
JavaScript
turned off. For that, you need to store a last-access time in the
session.
So, before serving a page, simple do this in your controller:

session[:last_access] = Time.now

Then before serving the next page:

redirect_to(:action => 'time_out' and return if session[:last_access] <
5.minutes.ago

I don't know if this applies to all actions in your controller or only
some
of them. If all of them, consider writing a before_filter.



dhashi wrote:
> Being new to Ruby or RoR itself - I was hoping someone could point me
> in the right direction to solve this problem.
>
> Thank you
>
> Dhashi
>
>
> >
>
>

--
View this message in context:
http://www.nabble.com/-Rails--Web-Page-Timer-tf317...
Sent from the RubyOnRails Users mailing list archive at Nabble.com.
A5d3e8b90c66904f218903b6a9f7b63e?d=identicon&s=25 dhashi (Guest)
on 2007-02-06 19:59
(Received via mailing list)
Thank you S.Ross for pointing the way!
I wish there was a way to give kudos to your account.

-Dhashi
This topic is locked and can not be replied to.