I am having a rails app that basically changes replaces images at pre-decided time. Now i want to create a ruby timer that triggers an event every second and when any image time is reached, it throws the event and the image changes in the view. I was thinking of usin开发者_StackOverflow中文版g observer pattern for this. Can anyone please advise me on how to go about doing this?
Any help is appreciated.
Have a look at gems that handle scheduled tasks for you. I've used Taskit quite successfully in the past.
http://ruby-toolbox.com/categories/scheduling.html
Sounds like you may also want image-rotating Javascript...
RubyOnRails is a server-side technology. It does not work in the way, which would let the rails application to change the 'view', after it has been rendered and sent to the client's browser.
You should use a JavaScript for this task.
You may decide who (client or the server) decides which image to serve. You may place all the URLs of the images in JavaScript, or you may provide a single resource in your rails application, which will return different images (or their URLs) in each request. There are many ways, but if I understood your question correctly, observers are not related to the problem.
精彩评论