在轮询服务器时,如何使用 Rails 3 更新灯箱的内容
在观看 Railscasts #229 轮询更改时,我试图实现相同的结果,只是我希望灯箱的内容动态更改,直到用户关闭它。
我有一个索引操作,它将迭代元素,对于每个元素,我将放置一个将打开灯箱的链接,然后它将自动轮询服务器,并更新灯箱中的内容(我正在使用 Colorbox)
所以,在index操作中:
- @systems.each do |system|
=link_to "Get Uname", get_uname_system_path(system), :remote => true
然后在get_uname操作中,我将调用js.erb
respond_to do |format|
format.js #get_uname.js.erb
end
最后在get_uname.js.erb文件中,我打开灯箱:
$.colorbox({html: "<div id=\"ajax-content\"></div>", innerWidth:425, innerHeight:344});
到目前为止,灯箱打开成功,但我不知道更新的内容它,每1秒...
While watching railscasts #229 Polling for Changes, I'm trying to achieve kind the same result, except that I want the content of a lightbox to dynamically be changed until user closes it.
I have an index action, that will iterate elements, and for every element, I'll put a link what will open the lightbox and then it will automatically poll the server, and update content within the lightbox (I'm using Colorbox)
So, in index action:
- @systems.each do |system|
=link_to "Get Uname", get_uname_system_path(system), :remote => true
Then in the get_uname action, I will call js.erb
respond_to do |format|
format.js #get_uname.js.erb
end
And finally in the get_uname.js.erb file, I open the lightbox:
$.colorbox({html: "<div id=\"ajax-content\"></div>", innerWidth:425, innerHeight:344});
Until now, The lightbox open successfully, but I don't know to update the content of it, every 1 sec...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用轮询可能对您有好处,但对我来说,最佳实践是 faye gem。您是 Railscast 粉丝,所以您设置此功能不会有问题。有了这个,您的灯箱将立即更新。
using polling might be good for you but to me the best practice for this is faye gem. you are a railscast fan so u would not have problem setting this up.. with this your light box would be updated instantly.