# Restful delete is driving me nuts

**URL:** <https://www.ruby-forum.com/t/restful-delete-is-driving-me-nuts/161796>\
**Category:** Rails\
**Created:** [March 2, 2009, 2:46pm UTC](https://www.ruby-forum.com/t/restful-delete-is-driving-me-nuts/161796 "2009-03-02T14:46:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jlf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c57346/32.png) [@jlf](https://www.ruby-forum.com/u/jlf)\
**Post date:** [March 2, 2009, 2:46pm UTC](https://www.ruby-forum.com/t/restful-delete-is-driving-me-nuts/161796/1 "2009-03-02T14:46:45Z")

</div>

Hi,

In my project, all delete links aren’t working. They keep acting as  
“show” action.

Here is an example for the announcements controller.

In routes.rb :

map.resources :announcements

In my index view, I have the standard  
\<%= link\_to ‘Destroy’, announcement, :confirm =\> ‘Are you  
sure?’, :method =\> :delete %\>

But when ever I click on the link, controller gets a “get” message,  
not a “delete”.

Processing AnnouncementsController#show (for 127.0.0.1 at 2009-03-02  
14:01:23) [GET]  
Session ID: 95ccbfa93eef0bf8408147c7b6b9a287  
Parameters: {“action”=\>“show”, “id”=\>“2”,  
“controller”=\>“announcements”, “locale”=\>“en”}

In order to get the delete working I had to create a new named route.

map.annoucements\_delete “announcements/:id/  
delete”, :controller=\>“announcements”, :action =\> “destroy”

\<%= link\_to ‘delete’, annoucements\_delete\_path(announcement), :confirm  
=\> ‘Are you sure?’, :method =\> :delete %\>

It works, but it is ugly.

What did I do wrong ?  
Thanks  
Jean-Loup

---

<div class="post-metadata">

**Author:** ![jlf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c57346/32.png) [@jlf](https://www.ruby-forum.com/u/jlf)\
**Post date:** [March 2, 2009, 4:36pm UTC](https://www.ruby-forum.com/t/restful-delete-is-driving-me-nuts/161796/2 "2009-03-02T16:36:38Z")

</div>

On Mon, Mar 2, 2009 at 5:20 AM, jlf [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> map.resources :announcements  
> Session ID: 95ccbfa93eef0bf8408147c7b6b9a287
> 
> It works, but it is ugly.
> 
> What did I do wrong ?  
> Thanks  
> Jean-Loup

In my very very small example, the following works for me:

_\<%= link\_to “delete”, announcement_\*\_path( **announcement** ), **:confirm  
=\>  
“Are you sure?”, :method =\> :delete** %\>\*

Good luck,

-Conrad

---

<div class="post-metadata">

**Author:** ![jlf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c57346/32.png) [@jlf](https://www.ruby-forum.com/u/jlf)\
**Post date:** [March 2, 2009, 5:31pm UTC](https://www.ruby-forum.com/t/restful-delete-is-driving-me-nuts/161796/3 "2009-03-02T17:31:03Z")

</div>

Do you have javascript enabled in the browser you’re testing the  
delete action with?

\<%= link\_to ‘Destroy’, announcement, :method =\> :delete %\> produces an  
anchor tag to the show action but with a bunch of javascript code to  
emulate the DELETE http method.
