Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

:confirm and :method not working in rails button_to

i am having a problem with my rails 3 app

In my view i have

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

The generated html is

<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>

my gem file is loading this

gem 'jquery-rails'

The following .js files are appearing in the generated 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> 

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

like image 515
Hishalv Avatar asked Dec 04 '22 21:12

Hishalv


1 Answers

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}) %>
like image 188
SomeDudeSomewhere Avatar answered Dec 07 '22 11:12

SomeDudeSomewhere