Forum: Ruby on Rails Restful delete/destroy

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
elle (Guest)
on 2009-03-25 05:31
(Received via mailing list)

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])

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

...and the index.html.erb has:
<% @ads.each do |ad| %>
  <li><%= link_to h(, ad %> [<%= link_to "Delete", ads_path
(ad), :method => :destroy %>]</li>
<% end %>

But instead of destroying a record, it creates a new empty record.
Also, when looking at the url of 'Delete' I get

Andrew B. (Guest)
on 2009-03-25 07:10
(Received via mailing list)
try changing the delete link to ad_path(ad) instead of ads_path(ad).
elle (Guest)
on 2009-03-25 07:28
(Received via mailing list)
I get:

Only get, put, and delete requests are allowed.

which I don't understand -- since isn't the request delete??
elle (Guest)
on 2009-03-25 10:06
(Received via mailing list)
1. As Andrew suggested, I used ad_path(ad) in singular

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

3. Changed the :method => :delete
so, my delete link ended up as:
<%= link_to 'Delete', ad_path(ad), :method => :delete %>

This topic is locked and can not be replied to.