# Destroy Action

**URL:** <https://www.ruby-forum.com/t/destroy-action/151287>\
**Category:** Rails\
**Created:** [October 19, 2008, 8:40pm UTC](https://www.ruby-forum.com/t/destroy-action/151287 "2008-10-19T20:40:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![keith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f05b48/32.png) [@keith](https://www.ruby-forum.com/u/keith)\
**Post date:** [October 19, 2008, 8:40pm UTC](https://www.ruby-forum.com/t/destroy-action/151287/1 "2008-10-19T20:40:15Z")

</div>

Hi Everyone,

I have just created a destroy action in my controller, it was working  
fine about 2 hours ago and now for some reason it has stopped working.  
Once I click on destroy I receive ’ Unknown action No action  
responded to destroy’. The action that I want it to redirect to is  
‘list’ and this action does work as I have another action that  
redirects to ‘list’ fine. Could anyone let me in to what I I have done  
wrong please…?

def list  
@albums = Album.find(:all)  
render(:action =\> ‘album\_list’)  
end

def destroy  
@album = Album.find(params[:id])  
@album.destroy  
redirect\_to(:action =\>‘list’)  
end

And in my view I have

\<% if @album != nil -%\>  
ID: \<%= @album.id %\>  
  
Title: \<%= @album.title %\>   
  
Artist: \<%= @album.artist %\>  
  
Genre: \<%= @album.genre %\>  
  
\<% else -%\>  
No record found.

```
  <% end -%>
  <%= link_to('Back', :action => 'alt_album_list') %> |
  <%= link_to('Edit', :action => 'edit', :id => @album.id ) %> |
  <%= link_to('Destroy', {:action => 'destroy', id =>

```

@album.id}, :confirm =\> ’  
Are you sure?’) %\>

When I go into the logs I get the following error message

Processing PublicController#destroy (for 127.0.0.1 at 2008-10-19  
16:32:19) [GET]  
Session ID:  
BAh7ByIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo  
SGFzaHsABjoKQHVzZWR7ADoMY3NyZl9pZCIlZmFlNWMzZDcxOWY5OTM0Yzhk  
ZDk0YTgwMDU4OWNkMDA=–5ecae299067ff9537732b80de514985b52f69fab  
Parameters: {“controller”=\>“public”, “action”=\>“destroy”,  
“id”=\>“15”}

ActionController::UnknownAction (No action responded to destroy):  
C:/Users/Keith/.netbeans/6.1/jruby-1.1/lib/ruby/gems/1.8/gems/  
actionpack-2.1.0/lib/action\_controller/filters.rb:580:in  
`call_filters' C:/Users/Keith/.netbeans/6.1/jruby-1.1/lib/ruby/gems/1.8/gems/ actionpack-2.1.0/lib/action_controller/filters.rb:573:in`perform\_action\_with\_filters’  
C:/Users/Keith/.netbeans/6.1/jruby-1.1/lib/ruby/gems/1.8/gems/  
actionpack-2.1.0/lib/action\_controller/benchmarking.rb:68:in  
`perform_action_with_benchmark' C:/Users/Keith/.netbeans/6.1/jruby-1.1/lib/ruby/1.8/benchmark.rb: 293:in`measure’  
C:/Users/Keith/.netbeans/6.1/jruby-1.1/lib/ruby/gems/1.8/gems/  
actionpack-2.1.0/lib/action\_controller/benchmarking.rb:68:in  
`perform_action_with_benchmark' C:/Users/Keith/.netbeans/6.1/jruby-1.1/lib/ruby/gems/1.8/gems/ actionpack-2.1.0/lib/action_controller/rescue.rb:201:in`perform\_action\_with\_rescue’  
C:/Users/Keith/.netbeans/6.1/jruby-1.1/lib/ruby/gems/1.8/gems/  
actionpack-2.1.0/lib/action\_controller/caching/sql\_cache.rb:13:in  
`perform_action_with_caching' C:/Users/Keith/.netbeans/6.1/jruby-1.1/lib/ruby/gems/1.8/gems/ activerecord-2.1.0/lib/active_record/connection_adapters/abstract/ query_cache.rb:33:in`cache’  
C:/Users/Keith/.netbeans/6.1/jruby-1.1/lib/ruby/gems/1.8/gems/  
activerecord-2.1.0/lib/active\_record/query\_cache.rb:8:in `cache' C:/Users/Keith/.netbeans/6.1/jruby-1.1/lib/ruby/gems/1.8/gems/ actionpack-2.1.0/lib/action_controller/caching/sql_cache.rb:12:in`perform\_action\_with\_caching’  
C:/Users/Keith/.netbeans/6.1/jruby-1.1/lib/ruby/gems/1.8/gems/  
actionpack-2.1.0/lib/action\_controller/base.rb:529:in `process' C:/Users/Keith/.netbeans/6.1/jruby-1.1/lib/ruby/gems/1.8/gems/ actionpack-2.1.0/lib/action_controller/filters.rb:569:in`process\_with\_filters’  
C:/Users/Keith/.netbeans/6.1/jruby-1.1/lib/ruby/gems/1.8/gems/  
actionpack-2.1.0/lib/action\_controller/session\_management.rb:130:in  
`process_with_session_management_support' C:/Users/Keith/.netbeans/6.1/jruby-1.1/lib/ruby/gems/1.8/gems/ actionpack-2.1.0/lib/action_controller/base.rb:389:in`process’  
C:/Users/Keith/.netbeans/6.1/jruby-1.1/lib/ruby/gems/1.8/gems/  
actionpack-2.1.0/lib/action\_controller/dispatcher.rb:149:in  
`handle_request' C:/Users/Keith/.netbeans/6.1/jruby-1.1/lib/ruby/gems/1.8/gems/ actionpack-2.1.0/lib/action_controller/dispatcher.rb:107:in`dispatch’  
C:/Users/Keith/.netbeans/6.1/jruby-1.1/lib/ruby/gems/1.8/gems/  
actionpack-2.1.0/lib/action\_controller/dispatcher.rb:104:in  
`synchronize' C:/Users/Keith/.netbeans/6.1/jruby-1.1/lib/ruby/gems/1.8/gems/ actionpack-2.1.0/lib/action_controller/dispatcher.rb:104:in`dispatch’  
C:/Users/Keith/.netbeans/6.1/jruby-1.1/lib/ruby/gems/1.8/gems/  
actionpack-2.1.0/lib/action\_controller/dispatcher.rb:120:in  
`dispatch_cgi' C:/Users/Keith/.netbeans/6.1/jruby-1.1/lib/ruby/gems/1.8/gems/ actionpack-2.1.0/lib/action_controller/dispatcher.rb:35:in`dispatch’  
C:/Users/Keith/.netbeans/6.1/jruby-1.1/lib/ruby/gems/1.8/gems/  
rails-2.1.0/lib/webrick\_server.rb:112:in `handle_dispatch' C:/Users/Keith/.netbeans/6.1/jruby-1.1/lib/ruby/gems/1.8/gems/ rails-2.1.0/lib/webrick_server.rb:78:in`service’  
C:/Users/Keith/.netbeans/6.1/jruby-1.1/lib/ruby/1.8/webrick/  
httpserver.rb:104:in `service' C:/Users/Keith/.netbeans/6.1/jruby-1.1/lib/ruby/1.8/webrick/ httpserver.rb:65:in`run’  
C:/Users/Keith/.netbeans/6.1/jruby-1.1/lib/ruby/1.8/webrick/  
server.rb:173:in `start_thread' :1:in`start’

Rendering C:/Users/Keith/.netbeans/6.1/jruby-1.1/lib/ruby/gems/1.8/  
gems/actionpack-2.1.0/lib/action\_controller/templates/rescues/  
layout.erb (not\_found)

Has anyone came across this before? I have done research on the  
message and someone has the same problem and fixed it by going into  
the following

This is a comment I found from another group

I got this error (ActionController::UnknownAction - No action  
responded to …), and I noticed it was because the link\_to helper  
generated bad URL’s (in the “:controller/:id/:action” format rather  
than “:controller/:action/:id”).

The fix was to change the order of statements in the config/routes.rb  
file; move my “map.resources” statements higher up in the file  
(=higher priority).

Thanks everyone

---

<div class="post-metadata">

**Author:** ![keith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f05b48/32.png) [@keith](https://www.ruby-forum.com/u/keith)\
**Post date:** [November 21, 2008, 7:36am UTC](https://www.ruby-forum.com/t/destroy-action/151287/2 "2008-11-21T07:36:28Z")

</div>

Moving "map.resources: highest did not work for me i moved  
map.resources :users to top but still my destroy method which was using  
:method =\> ‘post’, did not work untill i add the following in my  
routes.rb under the map.resources :users

map.connect ‘/users/:id/’, :controller =\> ‘users’, :action =\> ‘destroy’,  
:id =\> /\d+/

, so the new routes.rb (without comments #) looked like following:

ActionController::Routing::Routes.draw do |map|  
map.resources :users  
map.connect ‘/users/:id/’, :controller =\> ‘users’, :action =\>  
‘destroy’, :id =\> /\d+/

map.connect ‘:controller/:action/:id’  
map.connect ‘:controller/:action/:id.:format’  
end

I hope that helps

---

<div class="post-metadata">

**Author:** ![keith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f05b48/32.png) [@keith](https://www.ruby-forum.com/u/keith)\
**Post date:** [November 21, 2008, 7:56am UTC](https://www.ruby-forum.com/t/destroy-action/151287/3 "2008-11-21T07:56:26Z")

</div>

Baba Bobo wrote:

> Just tested even adding the following short version, also works fine:
> 
> map.connect ‘/users/:id/’, :controller =\> ‘users’, :action =\> ‘destroy’

sorry just tested while this short version fixes the ‘destroy’ method  
but it breaks the ‘new’ method so you will have to use the above  
mentioned full version which is:

map.connect ‘/users/:id/’, :controller =\> ‘users’, :action =\> ‘destroy’,  
:id =\> /\d+/

---

<div class="post-metadata">

**Author:** ![keith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f05b48/32.png) [@keith](https://www.ruby-forum.com/u/keith)\
**Post date:** [November 21, 2008, 7:38am UTC](https://www.ruby-forum.com/t/destroy-action/151287/4 "2008-11-21T07:38:34Z")

</div>

Just tested even adding the following short version, also works fine:

map.connect ‘/users/:id/’, :controller =\> ‘users’, :action =\> ‘destroy’
