Re: link_to with :method=>:delete not working ( Rails 3 )

<%= link_to "Delete", admin_question_path(question), :confirm => "Are you sure?", :method=>:delete %>

To make 'Delete' link work on Rails 3.0.5, I added prototype.js file and included following js in layout:

<%= csrf_meta_tag %>
<%= javascript_include_tag :defaults %>
<%= javascript_include_tag 'jquery-1.4.2.min','jquery.form','rails.js'%>

Re: link_to with :method=>:delete not working ( Rails 3 )

I did exactly that and wierd stuff happens. When I click cancel in the "Are you sure" dialog, the dialog closes and opens a new dialog, if I click cancel again it dosen't cancel the action.

I'm new to RoR, things like not getting a simple OK|Cancel dialog to work has several effects.
It seriously pisses me off, someone obviously diden't test things properly

It's as bad as the fact that the rake 0.9.0 cannot even do a db:create and that I cannot use bundle to correct the rake version (fails). I had to change the Gemfile.lock by hand to get rake db:create to work. Which makes me wonder why is rake 0.9.0 still out there for download? Lots of people must have run into that one.

If you cannot trust the framework with such a simple tasks, what happens when you get into real problems?

It's sold as the answer to all our prairs. But the time you gain in development you quickly lose in s--t like this.

Geee, I think I'll stay of RoR (by the by I run on x86-mingw32, ruby 1.9.2, rails 3.0.7)

Last edited by Kungen (2011-05-25 18:14:19)

Re: link_to with :method=>:delete not working ( Rails 3 )

HI ,

if you want to delete any record so create a delete link .

1) add link
<%= link_to "Delete", admin_question_path(question), :confirm => "Are you sure?", :method=>:delete %>

2) add  js in application.html.erb

<%= javascript_include_tag "rails" %>

I am sure it will work

Have a nice time

Last edited by sumit.shastri (2011-08-31 01:22:11)

Re: link_to with :method=>:delete not working ( Rails 3 )

Hi all,       
This is problem of javascrpt-helper of rails. You need to use rails.js appropriately. If you use prototype.js then in rails.js you need prototype helpers methods else if you use jquery then you need rails jquery helper.This link ( … c/rails.js   )  for jquery helper.

Last edited by chiru4all (2011-09-20 08:05:19)

Re: link_to with :method=>:delete not working ( Rails 3 )

Hi there,

  With javascript turned off, I am finding this problem of deletion not working either.
I have tried it in both rails 3.0.9 and rails 3.1.0.

It does however works out of the box when javascript on my browser is turned on.

The code is here, … without-js

The only things I did were:
1) create the project
2) rails generate scaffold Guitar name:string
3) rake db:migrate
4) script/rails server
5) Go to localhost:3000/guitars and create a new entry
6) Disable javascript on your browser
7) click on

Re: link_to with :method=>:delete not working ( Rails 3 )

I had the same problem and looked around various sources of rails support and used the above suggestions to get my work-in-progress application running again after a version 3.1.1 upgrade.  Since I was more familiar with Rails ver 2.x my knowledge of the changes is not in depth.  In addition to the javascript rails.js providing the missing solution, I also needed to know where to place the file and this was not obvious.

To save other new converts time, you need to place the rails.js file in your applications ./app/assets/javascript directory.

Re: link_to with :method=>:delete not working ( Rails 3 )

Semi-old thread now, but for future reference:

I'm not sure how far back this stretches, but as of Rails 3.1, in order to use :method with the link_to helper, you need to require jquery_ujs in your application.js - prototype.js and rails.js is no longer used.

While Max Williams is correct regarding the semantics of using a button rather than a link, a working implementation of :method => [:post|:put|:delete] will create a mini-form, just as your buttons, as well as adding a rel=