如何使用 :confirm 与 button_to 和 :method :put? [英] How to use :confirm with button_to and :method :put?

查看:40
本文介绍了如何使用 :confirm 与 button_to 和 :method :put?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些破坏性的动作要执行,所以我认为将这些动作放在 PUT 或 POST 后面是 Rails 的方式(所以 link_to 不起作用,因为它只能获取).

I have some destructive action to be performed, so I think it's Rails way to put such actions behind a PUT or POST (so link_to doesn't work because it only GETs).

我添加了一个这样的按钮:

I added a button like this:

<%= button_to "Acknowledge", ack_something_path, :method => :put, :confirm => "Sure?" %>

按钮有效(调用正确的操作),但是,我无法让 Rails 显示确认"对话框.

The button works (calls the correct action), but, I can't get Rails to show a "confirm" dialog box.

任何想法如何做到这一点?

Any ideas how to do that ?

更新(问题已解决)

我没有提到我在 HEAD 中包含了 jquery 和原型(我认为这无关紧要).但是,当我删除 jquery 时,显示了确认对话框.

I didn't mention that I was including jquery as well as prototype in HEAD (didn't think it would matter). BUT, when I removed jquery, the confirmation dialog was displayed.

不知道为什么会发生这种情况,但问题已解决(无论如何现在).jquery 和prototype 似乎不喜欢一起工作.

Don't know why this happens, but problem is solved (for now anyway). jquery and prototype do not like to work together it seems.

推荐答案

当我将您的代码复制到我的视图时,我可以显示确认对话框.

I could show the confirm dialog box when I copy your code to my view.

您是否在 <head> 部分包含了正确的 javascript 文件?需要 public/javascripts/rails.js 中的 js 文件来启用视图辅助方法中的所有 js 效果.

Did you include correct javascript file in the <head> section? The js file at public/javascripts/rails.js is needed to enable all the js effect in view helper methods.

您可以检查 <%= javascript_include_tag :defaults %> 是否在 head 中.

You can check whether <%= javascript_include_tag :defaults %> is in the head or not.

这篇关于如何使用 :confirm 与 button_to 和 :method :put?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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