Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performing AJAX delete operations restfully in rails

How do you perform delete and put operations restfully in rails? I have read the documentation and thought I was doing everything properly, but I can't seem to get it to work.

For example, if I wanted to delete an employee I would create a controller called "EmployeesController" and create a destroy method to perform the delete.

Then I went into the routes.rb file and entered map.resources :employees, which gives you access to the URL helper functions.

In whatever I want to call the Ajax operation from, I should just have a line like:

<%= link_to_remote "Delete", employee_path(@employee), :method => :delete %>

When I click on the link, it is still is sending a POST operation, so it does nothing.

What am I missing or doing wrong?

like image 497
Chris R. Avatar asked Oct 02 '08 14:10

Chris R.


1 Answers

Try

:url => employee_url(@employee)

IIRC, *_path is a named route generated by the :resource directive which includes the method, thus overwriting your :method => :delete

like image 179
Matthias Winkelmann Avatar answered Sep 28 '22 08:09

Matthias Winkelmann