在我的 Rails 应用程序中创建计时器
我有一个 Rails 应用程序,它基本上会在预先决定的时间更改替换图像。现在我想创建一个红宝石计时器,每秒触发一个事件,当达到任何图像时间时,它会抛出该事件并在视图中更改图像。我正在考虑为此使用观察者模式。谁能告诉我如何去做这件事吗?
任何帮助表示赞赏。
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 using observer pattern for this. Can anyone please advise me on how to go about doing this?
Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看为您处理计划任务的 gem。我过去使用 Taskit 非常成功。
http://ruby-toolbox.com/categories/scheduling.html
听起来你可能还想要图像旋转 Javascript...
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 是一种服务器端技术。它不会以这种方式工作,这会让 Rails 应用程序在渲染并发送到客户端浏览器后更改“视图”。
您应该使用 JavaScript 来完成此任务。
您可以决定由谁(客户端或服务器)决定提供哪个图像。您可以将图像的所有 URL 放在 JavaScript 中,也可以在 Rails 应用程序中提供单个资源,该资源将在每个请求中返回不同的图像(或其 URL)。有很多方法,但如果我正确理解你的问题,观察者与问题无关。
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.