我刚开始使用 ruby on rails 进行编码,我一直在遵循一个指南,该指南使用的 rails 版本比我使用的更过时。我正在使用 3.2.12
这是我的代码:
<%= button_to 'Destroy', product, :method => "delete", :confirm => 'Are you sure?' %>
据我了解,这些是传递给 rails 的符号,然后将其转换为 html 或 javascript 操作,然后弹出消息框并删除对象(如果适用)。上面的代码销毁了对象,但是并没有弹出确认框。为什么是这样?另外,我最初有以下内容:
<%= link_to 'Destroy', product, :method => "delete", :confirm => 'Are you sure?' %>
在任何情况下都不会弹出确认框,使用 link_to 或 button_to。下面是使用 Chrome 的检查器检查时呈现的 html。jquery 和 jquery-ujs 也被加载到了,所以我不确定从这里去哪里。
<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=">
谢谢!