:confirm和:method在rails button_to中不起作用 [英] :confirm and :method not working in rails button_to

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

问题描述

我的rails 3应用程序有问题

i am having a problem with my rails 3 app

我认为我有

<%= button_to("Accept Post", {}, {:confirm => "Are you sure?", :method => :accept_question, :remote => true}) %>

生成的html是

<form method="post" action="/questions/show/1" data-remote="true" class="button_to">
    <div>
        <input data-confirm="Are you sure?" type="submit" value="Accept Post" />
        <input name="authenticity_token" type="hidden" value="Rv1CbqkE+61Fn4wb836eOENjyGkNpzzRrwMTywLZPf0=" />
    </div>
</form>

我的gem文件正在加载

gem 'jquery-rails'

以下.js文件出现在生成的html中

<script src="/javascripts/jquery.js?1309961714" type="text/javascript"></script> 
<script src="/javascripts/jquery-ui.js?1309961714" type="text/javascript"></script> 
<script src="/javascripts/jquery-ui.min.js?1305044364" type="text/javascript"></script> 
<script src="/javascripts/jquery.min.js?1309961714" type="text/javascript"></script> 
<script src="/javascripts/jquery.tools.min.js?1309338309" type="text/javascript"> </scipt>
<script src="/javascripts/rails.js?1309961714" type="text/javascript"></script> 
<script src="/javascripts/application.js?1309424326" type="text/javascript"></script> 

我看到了与此主题相关的其他文章,但没有任何效果,我没有收到任何错误,只是重定向到同一页面,而没有提示.我还有其他一些使用jquery的代码,它们工作正常. 我遇到的问题是,确认和方法在继续之前没有提示.什么是在应用程序中实现jquery的好方法,我试图包括jrails,但是我所有其他代码都中断了感谢您的帮助

I have seen other posts on this topic, but nothing works, i get no error, just a redirect to the same page, without being prompted. I have other bits of code that use jquery, which work fine. the problem i have is that the confirm and method does not prompt be before continuing. What is a good way to implement jquery into an app, i have tried to include jrails, however all my other code breaks thanks for the help

推荐答案

我以前已经看到过此问题,并且我发现了使用纯JavaScript的解决方法.如果您着急的话,可能现在就可以了.

I've seen this problem before, and I just found a workaround, using pure JavaScript. If you are in a hurry this might just do for now.

您可以尝试执行此操作,并获得相同的效果:

You can try this and you get the same effect:

<%= button_to("Accept Post", {}, {:onclick => "return confirm('Are you sure?')", :method => :accept_question, :remote => true}) %>

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

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