button_to confirm not working

Hello,

I'm using the 'button_to' helper in the following syntax:

<td><%= button_to "Delete", { :action => "destroy", :id => user.id },             :confirm => "Are you sure?", :method => :delete, :class => 'submitLink' %></td>

However, the confirmation is not working, its going straight to the destroy action in the controller w/out confirming with the user in a popup. Any ideas?

Dave

loominator1970 wrote in post #962212:

Hello,

I'm using the 'button_to' helper in the following syntax:

<td><%= button_to "Delete", { :action => "destroy", :id => user.id },             :confirm => "Are you sure?", :method => :delete, :class => 'submitLink' %></td>

However, the confirmation is not working, its going straight to the destroy action in the controller w/out confirming with the user in a popup. Any ideas?

Is JavaScript turned on in your browser?

Dave

Best,

Is JavaScript turned on in your browser?

Yes, I have jQuery and protoype enabled in the application.html.erb page.

Is that "Yes I have JavaScript turned on in the browser _and_ I have jQuery and prototype enabled in application.html.erb" or "Yes, I have jQuery and protoype enabled in the application.html.erb and I didn't actually understand what you meant by Javascript turned on in the browser"?

If the former then have you checked the html to see if it is what you expect (View, Page Source or similar in browser) and it might be worth checking the html for validity by pasting the complete page html into the w3c html validator.

Colin

Actually, its C. "I'm a dumba$$ and didn't read your question carefully enough :)" Javascript IS turned on in my browser and enabled in my app. I will follow you suggestion and try that route. Thanks for the help!

Hello,

Is any method associated with it i your controller? like: def destroy @user.destroy   redirect_to.... end

For first shot for me it seems to be the problem, not JavaScript. Anyway I suggest Firebug to see if any JavaScript bug.

Let me know if further problem with it, good luck gezope

Zoltan Gero wrote in post #962389:

Hello,

Is any method associated with it i your controller? like: def destroy @user.destroy   redirect_to.... end

For first shot for me it seems to be the problem, not JavaScript.

No. The problem is that for some reason the JavaScript is not being generated, or at least not firing, as expected.

To the OP: do you see the generated JS in the page source?

Best,

Thanks for all the input, turns out I didn't have my javascript ducks in a row, since I'm a JS newb.

I'm going with an all jquery solution, and I needed to do the following things: # in the layouts/application.html.erb # remove the line <%= javascript_include_tag :defaults %> # and add.... <%= javascript_include_tag 'jquery-1.4.3.js', 'rails', 'application' %>

and in my public/javascripts directory add 'jquery-1.4.3.js' and 'rails.js' (from https://github.com/rails/jquery-ujs)

Works like a dream now!

Dave

loominator1970 wrote in post #964587:

and in my public/javascripts directory add 'jquery-1.4.3.js' and 'rails.js' (from GitHub - rails/jquery-ujs: Ruby on Rails unobtrusive scripting adapter for jQuery)

Works like a dream now!

Dave

I do as you do, however, it did not work. At last, i use this:

<%= button_to "del", @you, {:onclick => "return confirm('Are you sure?')", :method => :delete}%>

to solve the problem.

And this solution is from