# Explicit named routes with has\_many error

**URL:** <https://www.ruby-forum.com/t/explicit-named-routes-with-has-many-error/183685>\
**Category:** Rails\
**Created:** [February 18, 2010, 6:28pm UTC](https://www.ruby-forum.com/t/explicit-named-routes-with-has-many-error/183685 "2010-02-18T18:28:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![trev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dc4da7/32.png) [@trev](https://www.ruby-forum.com/u/trev)\
**Post date:** [February 18, 2010, 6:28pm UTC](https://www.ruby-forum.com/t/explicit-named-routes-with-has-many-error/183685/1 "2010-02-18T18:28:27Z")

</div>

I am very stuck on this problem. I know there is something simple I am  
missing, but I have been staring at it long enough to ask others at  
this point.

The code: [\_fixed.txt · GitHub](http://gist.github.com/307323)

Basically, I have an assets controller that is only accessible through  
users (you cannot view an asset without a user association). There are  
three stages to editing an asset, so instead of using the resources  
default :edit function and passing in query params, I decided to make  
cool named routes (i.e. /users/1/assets/1/edit/class), but I am  
getting “failed to generate” errors when I try to call the route I  
defined.

Can someone here take a minute and glance at my code to see what the  
frak I am doing wrong? I could use another set of eyes on this one.

## Thanks, trv

Trevor Lalish-Menagh  
[http://www.trevreport.org/](http://www.trevreport.org/)

---

<div class="post-metadata">

**Author:** ![trev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dc4da7/32.png) [@trev](https://www.ruby-forum.com/u/trev)\
**Post date:** [February 18, 2010, 8:36pm UTC](https://www.ruby-forum.com/t/explicit-named-routes-with-has-many-error/183685/2 "2010-02-18T20:36:40Z")

</div>

OK, I figured it out. Dumb mistake: to create an optional format like  
you see in `rake routes` as:  
classify\_user\_asset GET /users/:user\_id/assets/:id/edit/  
class(.:format) {:action=\>“classify”, :controller=\>“assets”}

you would write:  
map.with\_options :controller =\> ‘assets’, :conditions =\> {:method  
=\> :get} do |assets|  
assets.classify\_user\_asset ‘/users/:user\_id/assets/:id/edit/  
class’, :action =\> ‘classify’  
assets.classify\_user\_asset ‘/users/:user\_id/assets/:id/edit/  
class.:format’, :action =\> ‘classify’  
end

I was writing:  
map.with\_options :controller =\> ‘assets’, :conditions =\> {:method  
=\> :get} do |assets|  
assets.classify\_user\_asset ‘/users/:user\_id/assets/:id/edit/  
class(.:format)’, :action =\> ‘classify’  
end

because that is what I saw in `rake routes`.

Sorry for the n00b question, but I am glad I figured this out.

Yours,  
trv
