# Restful delete/destroy

**URL:** <https://www.ruby-forum.com/t/restful-delete-destroy/163813>\
**Category:** Rails\
**Created:** [March 25, 2009, 4:31am UTC](https://www.ruby-forum.com/t/restful-delete-destroy/163813 "2009-03-25T04:31:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![elle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ccd318/32.png) [@elle](https://www.ruby-forum.com/u/elle)\
**Post date:** [March 25, 2009, 4:31am UTC](https://www.ruby-forum.com/t/restful-delete-destroy/163813/1 "2009-03-25T04:31:22Z")

</div>

Hello,

I am sure this is a simple problem but for some reason I can’t get it  
to work.  
I am trying to delete a record. My routes.rb has:  
map.resources :ads

…the AdsController has:  
def destroy  
@ad = Ad.find(params[:id])  
@ad.destroy

```
respond_to do |format|
    format.html { redirect_to(ads_url) }
    format.xml { head :ok }
end

```

end

…and the index.html.erb has:

\<% @ads.each do |ad| %\> - \<%= link\_to h(ad.name), ad %\> [\<%= link\_to "Delete", ads\_path (ad), :method =\> :destroy %\>]
\<% end %\>

But instead of destroying a record, it creates a new empty record.  
Also, when looking at the url of ‘Delete’ I get  
[http://localhost:3000/ads.%23\<ad:0x24681b8\>](http://localhost:3000/ads.%23%3Cad:0x24681b8%3E)

TIA,  
Elle

---

<div class="post-metadata">

**Author:** ![elle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ccd318/32.png) [@elle](https://www.ruby-forum.com/u/elle)\
**Post date:** [March 25, 2009, 6:10am UTC](https://www.ruby-forum.com/t/restful-delete-destroy/163813/2 "2009-03-25T06:10:46Z")

</div>

try changing the delete link to ad\_path(ad) instead of ads\_path(ad).

---

<div class="post-metadata">

**Author:** ![elle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ccd318/32.png) [@elle](https://www.ruby-forum.com/u/elle)\
**Post date:** [March 25, 2009, 6:28am UTC](https://www.ruby-forum.com/t/restful-delete-destroy/163813/3 "2009-03-25T06:28:54Z")

</div>

I get:

ActionController::MethodNotAllowed  
Only get, put, and delete requests are allowed.

which I don’t understand – since isn’t the request delete??

---

<div class="post-metadata">

**Author:** ![elle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ccd318/32.png) [@elle](https://www.ruby-forum.com/u/elle)\
**Post date:** [March 25, 2009, 9:06am UTC](https://www.ruby-forum.com/t/restful-delete-destroy/163813/4 "2009-03-25T09:06:19Z")

</div>

Solved.

1. As Andrew suggested, I used ad\_path(ad) in singular

2. I left the name of the method as destroy, so:  
def destroy  
…  
end

3. Changed the :method =\> :delete  
so, my delete link ended up as:  
\<%= link\_to ‘Delete’, ad\_path(ad), :method =\> :delete %\>

Thanks,  
Elle
