# Problems with destroy

**URL:** <https://www.ruby-forum.com/t/problems-with-destroy/81765>\
**Category:** Rails\
**Created:** [January 13, 2007, 4:17am UTC](https://www.ruby-forum.com/t/problems-with-destroy/81765 "2007-01-13T04:17:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [January 13, 2007, 4:17am UTC](https://www.ruby-forum.com/t/problems-with-destroy/81765/1 "2007-01-13T04:17:37Z")

</div>

Hello:

I have a destroy method in my controller - pretty standard:

def destroy  
@goal = Goal.find(params[:id])  
respond\_to do |format|  
format.html { redirect\_to goals\_url }  
format.xml { head :ok }  
end  
end

And then I have a listing view which has the destroy method in the view

- also pretty standard:

\<%= link\_to ‘Delete’, { :action =\> ‘destroy’, :id =\> goal }, :confirm =\>  
‘Are you sure?’, :post =\> true %\>&nbsp|&nbsp

where the id = goal id - no problem retreiving that, becuase i see it in  
my URL:

[[myurl.com](http://myurl.com)]/goals/13

but this is called, I get an error:

Unknown action

No action responded to 13

How can this be the case when the destroy method is correctly being  
referenced in my view?

Thank you very much in advance for any help you can provide.

Mike

---

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [January 13, 2007, 5:55am UTC](https://www.ruby-forum.com/t/problems-with-destroy/81765/2 "2007-01-13T05:55:22Z")

</div>

The url ([[myurl.com](http://myurl.com)]/goals/13) looks like one of the new  
“resource-based” urls from Rails 1.2, but it seems like the routing  
system is expecting an old-style url ([[myurl.com](http://myurl.com)]/goals/destroy/13). If  
you are using the new routing then it seems like you’ve somehow mixed up  
the two systems. I don’t know much about the new system, but I know that  
if you’re using it you should have a line like the following in your  
routes.rb file:

map.resources :goals

Do you have this?

I you still can’t figure out the problem, please post your routes.rb  
file - it might provide some more clues about what’s going wrong.

---

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [January 13, 2007, 4:39pm UTC](https://www.ruby-forum.com/t/problems-with-destroy/81765/3 "2007-01-13T16:39:18Z")

</div>

Thanks so much for your reply. I think I do have a mix of routing  
systems, but I’m not sure how it works. Does rails have a doc outlining  
how routes in 1.2 works? here’s my config/routes.rb file:

ActionController::Routing::Routes.draw do |map|  
map.resources :goals\_tags

map.resources :tags

map.resources :goals

map.connect ‘’, :controller =\> “goals”

# The priority is based upon order of creation: first created -\>

highest priority.

# Sample of regular route:

# map.connect ‘products/:id’, :controller =\> ‘catalog’, :action =\>

‘view’

# Keep in mind you can assign values other than :controller and

:action

# Sample of named route:

# map.purchase ‘products/:id/purchase’, :controller =\> ‘catalog’,

:action =\> ‘purchase’

# This route can be invoked with purchase\_url(:id =\> product.id)

# You can have the root of your site routed by hooking up ‘’

# – just remember to delete public/index.html.

# map.connect ‘’, :controller =\> “welcome”

# Allow downloading Web Service WSDL as a file with an extension

# instead of a file named ‘wsdl’

map.connect ‘:controller/service.wsdl’, :action =\> ‘wsdl’

# Install the default route as the lowest priority.

```
map.connect ':controller/:action/:id.:format'

```

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

end

Thanks again - any help you can provide.

---

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [January 13, 2007, 5:46pm UTC](https://www.ruby-forum.com/t/problems-with-destroy/81765/4 "2007-01-13T17:46:51Z")

</div>

> \<%= link\_to ‘Delete’, { :action =\> ‘destroy’, :id =\> goal }, :confirm =\>  
> ‘Are you sure?’, :post =\> true %\>&nbsp|&nbsp

I’m not sure if this is the problem, but could you try using the  
following link in your view instead:

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

This appears to be the preferred way of writing links with the new  
routing - it may be the only way. Don’t ask me how it works though - I  
haven’t worked it out yet myself.

There does appear to be some “hidden” documentation for this in the  
“resources.rb” file in the rails source. For some reason it’s marked  
with a #:nodoc: tag, so it doesn’t appear in the generated  
documentation. I don’t know whether this was just an oversight or  
whether the documentation is not considered satisfactory.

---

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [January 19, 2007, 4:29pm UTC](https://www.ruby-forum.com/t/problems-with-destroy/81765/5 "2007-01-19T16:29:52Z")

</div>

On Jan 12, 2007, at 10:17 PM, Mike D. wrote:

> my URL:  
> referenced in my view?  
> I’m guessing you’re mapping ‘goals’ as a resource in your routes.rb  
> file? If so, you’ll need to specify the ‘delete’ method explicitly. Try:

\<%= link\_to ‘Delete’, { :action =\> ‘destroy’, :id =\> goal }, :confirm =\>  
‘Are you sure?’, :method =\> ‘delete’ %\>

James.

---

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [January 19, 2007, 4:29pm UTC](https://www.ruby-forum.com/t/problems-with-destroy/81765/6 "2007-01-19T16:29:53Z")

</div>

\<…\>

> There does appear to be some “hidden” documentation for this in the  
> “resources.rb” file in the rails source. For some reason it’s marked  
> with a #:nodoc: tag, so it doesn’t appear in the generated  
> documentation. I don’t know whether this was just an oversight or  
> whether the documentation is not considered satisfactory.

You can try this:  
[http://caboo.se/doc/classes/ActionController/Resources.html](http://caboo.se/doc/classes/ActionController/Resources.html)

## Regards, Rimantas

[http://rimantas.com/](http://rimantas.com/)
