使用 Ruby on Rails 的 Ajax 弹出框
这是一个非常基本的问题,但我找不到一个好的答案。我的 Rails 应用程序中有一个页面,其中有许多可以“标记”的对象。单击标志按钮应显示一个带有确认信息、小表单等的小框。问题是我不知道如何使用 RJS 模板来执行此操作。
我一直在使用 page.insert_html 但这需要一个 ID。为了完成这项工作,我必须为每个可以标记的事物分配一个唯一的 ID。这看起来不太干净,仍然让我想知道如何确保只能显示一个表单并且该框在提交时消失。这个问题有更简单的解决办法吗?我本质上想创建一些类似于出现在 SO 上的标志框的东西。抱歉,我对 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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 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).
Sounds like the way to go.
jQuery UI 还有一个 Dialog 小部件,非常适合此类事情。这是一个不错的小部件,您可以自定义您的 jQuery UI 库以包含(或排除,如果您想要将更精简的 javascript 传递到浏览器)其他方便的小部件(手风琴、进度条等),请
查看 jQuery 对话框
jQuery UI also has a Dialog widget that works really well for this sort of thing. It's a nice widget and you can customize your jQuery UI library to include (or exclude if you want a slimmer javascript passed to the browser) other handy widgets as well (accordion, progressbar, etc)
Check out the Dialog examples at jQuery Dialog