# Nested URL Routing

**URL:** <https://www.ruby-forum.com/t/nested-url-routing/138431>\
**Category:** Rails\
**Created:** [May 22, 2008, 11:34pm UTC](https://www.ruby-forum.com/t/nested-url-routing/138431 "2008-05-22T23:34:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![summea](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3ec8ea/32.png) [@summea](https://www.ruby-forum.com/u/summea)\
**Post date:** [May 22, 2008, 11:34pm UTC](https://www.ruby-forum.com/t/nested-url-routing/138431/1 "2008-05-22T23:34:26Z")

</div>

Hi everyone,

I’ve been reading a lot of posts related to routing and URLS in Rails  
lately but I still can’t figure out how to do this:

I have a controller (categories) where I’m using the BetterNestedSet  
plugin in order to have a tree structure for categories for my web  
project. A “category” is basically like a folder.

I also have another controller (pages) where each “page” is  
essentially an HTML-like page. Each “page” is filed underneath a  
certain “category”. All of this seems to work at the moment. But I  
can’t seem to find any information on how to display a “page” as if it  
were filed (like an HTML file in a web directory.) So that it would  
look something like this:

> **[Overview](https://www.salesforce.com/products/platform/overview/?d=70130000000liBh&internal=true&bc=HA)**
>
> Go digital fast and empower your teams to work from anywhere. Develop scalable, custom business apps with low-code development or give your teams the tools to build with services and APIs.

Maybe this is the point where you (the reader,) are wondering, “why is  
he doing it THIS way…?” And if so, is there a better way to do  
this? I realize that if I eventually need to move a page to another  
“category” the URL where it was at previously will now be broken. But  
for a simple website application it works for me.

Is there a way to have a route that allows for potentially unlimited  
directories in the URL?

thanks,

andy

---

<div class="post-metadata">

**Author:** ![summea](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3ec8ea/32.png) [@summea](https://www.ruby-forum.com/u/summea)\
**Post date:** [May 23, 2008, 5:03am UTC](https://www.ruby-forum.com/t/nested-url-routing/138431/2 "2008-05-23T05:03:04Z")

</div>

On Thu, May 22, 2008 at 5:33 PM, summea [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Maybe this is the point where you (the reader,) are wondering, “why is  
> he doing it THIS way…?” And if so, is there a better way to do  
> this? I realize that if I eventually need to move a page to another  
> “category” the URL where it was at previously will now be broken. But  
> for a simple website application it works for me.
> 
> Is there a way to have a route that allows for potentially unlimited

Yep, you can use route globbing:

map.file ‘\*directory/:file’, :requirements =\> {:file =\> /\w+.\w+/}  
map.directory ‘\*directory’

Then to generate lins to these URLs:

directory\_path([‘path’, ‘to’, ‘dir’])  
file\_path([‘path’, ‘to’, ‘dir’], ‘file.txt’)

The trick with globbing is that you need to have parts in your URL that  
either conform to some requirements, or have a unique piece in them.  
Otherwise, any route will match that route.

Hope that helps.

Brandon
