:确认在rails中不起作用 [英] :confirm in rails not working

查看:105
本文介绍了:确认在rails中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始在rails上用ruby编码,我一直在遵循一个指南,该指南使用的Rails版本比我使用的版本更多.我正在使用3.2.12

I just started coding in ruby on rails and I've been following a guide which is using a more outdated version of rails than I am using. I am using 3.2.12

这是我的代码:

<%= button_to 'Destroy', product, :method => "delete", :confirm => 'Are you sure?'  %>

据我了解,这些是传递到rails的符号,然后将它们转换为html或javascript操作,然后弹出消息框并删除对象(如果适用).上面的代码销毁了对象,但没有弹出确认框.为什么是这样?另外,我起初具有以下几点:

From what I understand, these are symbols that are passed to rails, which is then converted to either an html or javascript action that then pops up the message box and deletes the object if applicable. The above code destroys the object, but it does not pop up the confirm box. Why is this? Also, I had the above as the following at first:

<%= link_to 'Destroy', product, :method => "delete", :confirm => 'Are you sure?'  %>

在任何情况下,使用link_to或button_to都不会弹出确认框.以下是使用Chrome的检查器检查时呈现的html. jQuery和jquery-ujs也都加载到了,所以我不确定从这里去哪里.

The confirm box is not popping up under any circumstance, using link_to or button_to. Below is the html rendered when inspected using Chrome's inspector. jquery and jquery-ujs are loaded into the as well, so I'm not sure where to go from here.

<input name="_method" type="hidden" value="delete">
<input data-confirm="Are you sureeee?" type="submit" value="Destroy">
<input name="authenticity_token" type="hidden" value="Q2xicqELHYHtrwarbtPBe5PT2bZgWV5C+JdcReJI8ig=">

谢谢!

推荐答案

我必须在数据属性中添加我的Confirm属性才能使其正常工作.我正在使用带有Bootstrap的Rails 4.我希望这可以帮助遇到此问题的其他人.

I had to add my confirm attribute inside the data attribute to get it to work. I am using rails 4 with bootstrap. I hope this helps someone else who has that issue.

link_to 'Delete', @rule, method: :delete, data: { confirm: 'Are you sure you want to delete this alert?' }

这篇关于:确认在rails中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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