使用 Ruby on Rails 的 Ajax 弹出框

Ajax pop up box using Ruby on Rails(使用 Ruby on Rails 的 Ajax 弹出框)

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

问题描述

这是一个非常基本的问题,但我找不到一个好的答案.我的 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 脸盒.这种事情最好不要在 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 弹出框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:使用 Ruby on Rails 的 Ajax 弹出框

基础教程推荐