# Nested routes (2)

**URL:** <https://www.ruby-forum.com/t/nested-routes-2/124028>\
**Category:** Rails\
**Created:** [December 23, 2007, 7:20pm UTC](https://www.ruby-forum.com/t/nested-routes-2/124028 "2007-12-23T19:20:32Z")\
**Posts on this page:** 3\
**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:** [December 23, 2007, 7:20pm UTC](https://www.ruby-forum.com/t/nested-routes-2/124028/1 "2007-12-23T19:20:32Z")

</div>

Rails 2.0.2

I am trying to rewrite my app routes to follow a good RESTFul pattern in  
the 2.0app version…

I have a single resource ‘user’ and nested resource  
map.resource :user, :controller =\> “users”, :member =\> {:network =\>  
:get} do |user|  
…  
user.resources :relationships, :collection =\> {:network =\> :get,  
:direct =\> :get, }  
…  
end

which is called by formatted\_network\_user\_relationships for the  
current user (logged in)

a dynamic network structure is built (xml format) and display by a flash  
object

but writing this, it just give me the first level, clicking on a flash  
‘user’ object must call the relationships network for the clicked user

something like formatted\_network\_users\_relationships(:clicked\_id)  
to get  
/users/\<clicked\_id\>/relationships/network.xml

should I defined another resource ‘users’ , or is this the case for a  
domain name ?

what kind of new route I should write …

thanks

kad

---

<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:** [December 23, 2007, 7:44pm UTC](https://www.ruby-forum.com/t/nested-routes-2/124028/2 "2007-12-23T19:44:16Z")

</div>

> to get  
> /users/\<clicked\_id\>/relationships/network.xml
> 
> should I defined another resource ‘users’ , or is this the case for a  
> domain name ?
> 
> what kind of new route I should write …
> 
> thanks
> 
> kad

Don’t know if it’s the best one, but I found a solution, passing the  
clicked\_id as a parameter, and using it in the controller

so I have /user/relationships/network.xml?clicked\_id= nnn

---

<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:** [December 23, 2007, 10:36pm UTC](https://www.ruby-forum.com/t/nested-routes-2/124028/3 "2007-12-23T22:36:35Z")

</div>

You should use named route for this case. So if you want  
/users/\<clicked\_id\>/relationships/network.xml

define name route like this:

map.network ‘/users/:clicked\_id/relationships’, :controller =\>  
‘your\_controller’, :action =\> ‘network’

when you do rake routes, you will see the URL helper method for this  
definition use that with the clicked\_id as the parameter.

On Dec 23, 2007 10:20 AM, Kad K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> a dynamic network structure is built (xml format) and display by a flash  
> domain name ?
> 
> what kind of new route I should write …
> 
> thanks
> 
> ## kad

–  
[http://www.rubyplus.org/](http://www.rubyplus.org/)  
Free Ruby Screencasts
