# Routing to arbitrary deeply nested resources

**URL:** <https://www.ruby-forum.com/t/routing-to-arbitrary-deeply-nested-resources/111207>\
**Category:** Rails\
**Created:** [August 3, 2007, 8:35pm UTC](https://www.ruby-forum.com/t/routing-to-arbitrary-deeply-nested-resources/111207 "2007-08-03T20:35:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BallS\_Donald\_A\_Jr\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/da6949/32.png) [@BallS\_Donald\_A\_Jr\_S](https://www.ruby-forum.com/u/BallS_Donald_A_Jr_S)\
**Post date:** [August 3, 2007, 8:35pm UTC](https://www.ruby-forum.com/t/routing-to-arbitrary-deeply-nested-resources/111207/1 "2007-08-03T20:35:50Z")

</div>

I’ve got a tree of nodes to which I want to route requests. Currently  
I’m using simple resource routing:

map.resources :nodes

Rather than a flat URLspace where all nodes are access via:

/nodes/id

I’d prefer an arbitrary deeply nested URLspace:

/nodes/id  
/nodes/id/child  
/nodes/id/child/grandchild

Both to make inserting new nodes simpler, and to make context-specific  
searching easier.

Can anyone suggest how I might approach this problem?

- donald

---

<div class="post-metadata">

**Author:** ![BallS\_Donald\_A\_Jr\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/da6949/32.png) [@BallS\_Donald\_A\_Jr\_S](https://www.ruby-forum.com/u/BallS_Donald_A_Jr_S)\
**Post date:** [August 4, 2007, 1:37am UTC](https://www.ruby-forum.com/t/routing-to-arbitrary-deeply-nested-resources/111207/2 "2007-08-04T01:37:25Z")

</div>

Ball, Donald A Jr (Library) wrote:

> /nodes/id  
> /nodes/id/child  
> /nodes/id/child/grandchild
> 
> Both to make inserting new nodes simpler, and to make context-specific  
> searching easier.
> 
> Can anyone suggest how I might approach this problem?
> 
> - donald

Use \* and write your own routing method? E.g.:

map.connect ‘nodes/\*rparams’,  
:controller =\> “nodes”,  
:action =\> “router”

and rparams will be passed into router as an array of values.

–  
Michael W.

---

<div class="post-metadata">

**Author:** ![BallS\_Donald\_A\_Jr\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/da6949/32.png) [@BallS\_Donald\_A\_Jr\_S](https://www.ruby-forum.com/u/BallS_Donald_A_Jr_S)\
**Post date:** [August 6, 2007, 4:59pm UTC](https://www.ruby-forum.com/t/routing-to-arbitrary-deeply-nested-resources/111207/3 "2007-08-06T16:59:30Z")

</div>

> > I’d prefer an arbitrary deeply nested URLspace:
> > 
> > - donald
> 
> Use \* and write your own routing method? E.g.:
> 
> map.connect ‘nodes/\*rparams’,  
> :controller =\> “nodes”,  
> :action =\> “router”
> 
> and rparams will be passed into router as an array of values.

That’s a thought, thanks for the suggestion. Sadly, it means I can’t use  
any of the nice url generator methods provided by rails routing, but  
it’d work. I’ll give it a whirl.

- donald
