# REST routes :has\_many , new style

**URL:** <https://www.ruby-forum.com/t/rest-routes-has-many-new-style/112996>\
**Category:** Rails\
**Created:** [August 25, 2007, 5:25pm UTC](https://www.ruby-forum.com/t/rest-routes-has-many-new-style/112996 "2007-08-25T17:25:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [August 25, 2007, 5:25pm UTC](https://www.ruby-forum.com/t/rest-routes-has-many-new-style/112996/1 "2007-08-25T17:25:02Z")

</div>

I am trying to write a nested route ‘new style’

map.resources :franchises, :has\_many =\> :documents

in place of the :

map.resources :franchises do |franchises|  
franchises.resources :documents, :name\_prefix =\> “franchise\_”  
end

but get an error :  
no route found to match “/franchises/1/documents” with {:method=\>:get}

running rake routes, cannot see it…  
what could be the problem with my Rail install ?

thanks

---

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [August 25, 2007, 9:19pm UTC](https://www.ruby-forum.com/t/rest-routes-has-many-new-style/112996/2 "2007-08-25T21:19:36Z")

</div>

Kad K. wrote:

> but get an error :  
> no route found to match “/franchises/1/documents” with {:method=\>:get}

Shouldn’t ‘franchise’ be singular when used with an id?

---

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [August 25, 2007, 11:31pm UTC](https://www.ruby-forum.com/t/rest-routes-has-many-new-style/112996/3 "2007-08-25T23:31:54Z")

</div>

John M. wrote:

> Kad K. wrote:
> 
> > but get an error :  
> > no route found to match “/franchises/1/documents” with {:method=\>:get}
> 
> Shouldn’t ‘franchise’ be singular when used with an id?

I tried it too…  
no route found to match “/franchise/1/documents” with {:method=\>:get}

a rake routes doesn’t show up any nested route for documents, it seems  
the :has\_many is not seen at all

---

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [August 26, 2007, 12:20am UTC](https://www.ruby-forum.com/t/rest-routes-has-many-new-style/112996/4 "2007-08-26T00:20:34Z")

</div>

Hi –

On Sat, 25 Aug 2007, Kad K. wrote:

> but get an error :  
> no route found to match “/franchises/1/documents” with {:method=\>:get}
> 
> running rake routes, cannot see it…  
> what could be the problem with my Rail install ?

Are you running edge Rails? If not, :has\_many won’t work.

I’ve put your map.resources line in my routes.rb, and I get this in  
the console:

> > r = ActionController::Routing::Routes  
> > =\> # lots of output…  
> > r.recognize\_path(“/franchises/1/documents”, :method =\> :get)  
> > =\> {:controller=\>“documents”, :action=\>“index”, :franchise\_id=\>“1”}

This is on revision 7340 (a fairly recent edge Rails).

David

–

- Books:  
RAILS ROUTING (new! [http://www.awprofessional.com/title/0321509242](http://www.awprofessional.com/title/0321509242))  
RUBY FOR RAILS ([Ruby for Rails](http://www.manning.com/black))
- Ruby/Rails training  
& consulting: Ruby Power and Light, LLC ([http://www.rubypal.com](http://www.rubypal.com))

---

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [September 25, 2007, 12:22am UTC](https://www.ruby-forum.com/t/rest-routes-has-many-new-style/112996/5 "2007-09-25T00:22:42Z")

</div>

David,  
I am trying to figure out if this is the intended behaviour  
map.resources :users,  
:has\_many =\> [:groups]

map.resources :groups, :collection =\> {:joined =\> :get, :created =\>  
:get}

in console I type

> > r = ActionController::Routing::Routes  
> > r.recognize\_path("/groups/created", :method =\> :get)  
> > =\> {:controller=\>“groups”, :action=\>“created”}

> > r.recognize\_path("/users/diego/groups/created", :method =\> :get)  
> > =\> {:controller=\>“groups”, :user\_id=\>“diego”, :action=\>“show”,  
> > :id=\>“created”}

the collections routes for groups are not carried over into the nested  
version inside of user.  
Furthermore there is no syntax like has\_many =\> [:posts =\>  
{:collections =\> {:joined =\> :get} } ] in place.

I am guessing that my only options is to repeat any :new, :member or  
:collections specific routes.

Am I guessing right?

Diego
