Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

:confirm option in Rails being ignored while using Rails 3 and jQuery UJS

I've got a table of projects in my Rails app, each with a delete link, like so:

<%= link_to "Delete", project, :confirm => "Are you sure?", :method => :delete %>

However, the delete request is sent even if the user clicks "Cancel" on the dialog box.

Any ideas on how to fix this? I'm using Rails 3, Beta 3, with the jQuery library and accompanying jQuery UJS library.

like image 324
peehskcalba Avatar asked Jan 23 '23 01:01

peehskcalba


2 Answers

You need to get a more recent version of rails.js. I was having the same problem using the same setup you have. When I diff'd the old and new versions, I discovered the confirmation handler in the old version was commented out. The new version solves the problem.

like image 53
Rick Avatar answered Jan 30 '23 13:01

Rick


Download rails.js from (http://github.com/rails/jquery-ujs/blob/master/src/rails.js) if you are using jQuery and put it in your public/javascripts folder.

Then make sure you have the following on your template's header

<%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js" %>
<%= javascript_include_tag 'rails' %>
<%= csrf_meta_tag %>

And that's it =)

like image 39
Carlos A. Cabrera Avatar answered Jan 30 '23 14:01

Carlos A. Cabrera