使用Ruby on Rails Ajax的弹出框 [英] Ajax pop up box using Ruby on Rails

查看:692
本文介绍了使用Ruby on Rails Ajax的弹出框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个pretty的基本问题,但我找不到它一个很好的答案。我有一个网页在我的Rails应用程序那里是可以'标记'许多对象。点击该标志的按钮将显示一个确认,小表等麻烦的是我无法弄清楚如何使用RJS模板做这一个小盒子。

This is a pretty basic question but I can't find a good answer for it. I have a page in my Rails app where there are many objects that can be 'flagged'. Clicking the flag button should display a little box with a confirmation, little form, etc. The trouble is I can't figure out how to do this using RJS templates.

我一直在使用page.insert_html但这需要一个ID。为了使这项工作,我不得不指派只能标记一个唯一的ID每一件事。这似乎不是很干净,仍然让我想了解一下,确保只有一种形式可以显示和控制框消失上提交。有没有更简单的解决这个问题呢?我基本上是想创建一个类似于出现在SO的标志旗箱子的东西。对不起,我是比较新的RJS模板。谢谢你。

I've been using page.insert_html but this requires an ID. In order to make this work I had to assign each thing that can be flagged a unique ID. This doesn't seem very clean and still leaves me wondering about making sure only one form can be displayed and that the box disappears on submit. Is there a more simple solution this problem? I essentially want to create something similar to the flag boxes that appear on SO for a flag. Sorry, I'm relatively new to RJS templates. Thanks.

推荐答案

您可以用做到这一点jQuery的facebox 。这种事情最好不要在RJS完成,但在不显眼的JavaScript,这就是每个人都在往这些天,这是干净多了。您可以将facebox REL到你的链接,那么当点击它可以在弹出窗口中打开窗体。

You could do this with the jquery facebox. This kind of thing is better not done in rjs, but in unobtrusive javascript, that's where everyone is heading these days, it's much cleaner. You can attach the facebox rel to your links, then when clicked it can open the form in a popup window.

然后在您的弹出式窗口中,你可以做你的形式和重定向或什么的。用户将只能单击其中一个时,弹出窗口打开叠加放置在页面,以便点击之外,要么没有效果或关闭的形式(我想你的配置选择)作为。

Then in your popup window you can do your form and redirect or whatever. The user will be only able to click one as when the pop up window opens an overlay is put over the page so clicking outside it either has no effect or closes the form (I think you choose in the config).

听起来像是要走的路。

这篇关于使用Ruby on Rails Ajax的弹出框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆