Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm having trouble with my verbs in Rails...

viewing a page for a resource (Dog) which has_many (Fleas). Embedded in dog's show.html.haml is a call to render @dog.fleas which automatically(?) finds & uses the template in "fleas/_flea.html.haml" to list each flea associated with said dog.

this displays correctly. whew! Now, next to each flea I've put a "Kill Flea" link that goes to a url: //localhost:3000/dogs/1/fleas/7. Which is generated by:

= link_to("Kill Flea", [ flea.dog, flea ], :method => :delete, :confirm => "Sure? A bunny will die")

but every time that link is clicked there is no confirmation... and it renders the flea's show.html page. it's as if it's using GET on /dogs/1/fleas/7 instead of DELETE?!?

ps- not worried about spiders & robots deleting things in my database... i'm just trying to learn Rails..and understand what's happening

like image 702
Meltemi Avatar asked Dec 03 '10 03:12

Meltemi


1 Answers

Rails 3 uses unobtrusive javascript now. In Rails 2.3, erb would just shove all that messy javascript right into the link itself, in an onClick event. Now the javascript has been moved out of the link, and into external js files. Make sure you have this in your layout:

<%= javascript_include_tag :all %>

If you do have this, there might be deeper problems keeping your javascript from running, but this is the place to start. Let me know how it turns out.

like image 168
Jaime Bellmyer Avatar answered Oct 05 '22 09:10

Jaime Bellmyer