# Cms like routes

**URL:** <https://www.ruby-forum.com/t/cms-like-routes/176147>\
**Category:** Rails\
**Created:** [September 25, 2009, 10:09am UTC](https://www.ruby-forum.com/t/cms-like-routes/176147 "2009-09-25T10:09:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fredd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ecccb3/32.png) [@fredd](https://www.ruby-forum.com/u/fredd)\
**Post date:** [September 25, 2009, 10:09am UTC](https://www.ruby-forum.com/t/cms-like-routes/176147/1 "2009-09-25T10:09:31Z")

</div>

Hi! I need to be able to construct urls that looks something like  
this: news/sport/1-article. The news/sport part is a section that an  
article can be posted in. The idea is that sections can be nested and  
that it should be reflected in the url. How’s that possible to do  
without globbing the whole route to a custom controller and then break  
it apart?

I tried something like this in the routes.rb without any luck:  
map.connect ‘\*section/:id’, :controller =\> ‘articles’, :action =\>  
‘show’. If I change it to map.connect ‘\*section/articles/:id’ it  
works but then i need that articles part in the routes all the time,  
not a very good solution:)

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![fredd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ecccb3/32.png) [@fredd](https://www.ruby-forum.com/u/fredd)\
**Post date:** [September 26, 2009, 2:48pm UTC](https://www.ruby-forum.com/t/cms-like-routes/176147/2 "2009-09-26T14:48:13Z")

</div>

I think I solved it my self actually!

It turns out that if you name the id parameter something else (like  
article\_id) Rails actually divides the params correctly.

So this route:  
map.article\_by\_id ‘\*sections/:article\_id’, :controller =\>  
“articles”, :action =\> “show”, :article\_id =\> /\d|\d-(.+)/  
would detect something like this:  
news/sports/football/4  
and Rails would route to the article controller and show action width  
the following params: {“sections”=\>[“news”, “sports”, “football”],  
“article\_id”=\>“4”}

Pretty cool, and hopefully this helps someone else with the same  
problem that I had.

---

<div class="post-metadata">

**Author:** ![fredd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ecccb3/32.png) [@fredd](https://www.ruby-forum.com/u/fredd)\
**Post date:** [September 26, 2009, 2:51pm UTC](https://www.ruby-forum.com/t/cms-like-routes/176147/3 "2009-09-26T14:51:44Z")

</div>

I think I solved it my self actually!  
It turns out that if you name the id parameter something else (like  
article\_id) Rails actually divides the params correctly.  
So this route:  
map.article\_by\_id ‘\*sections/:article\_id’, :controller =\>  
“articles”, :action =\> “show”, :article\_id =\> /\d|\d-(.+)/  
would detect something like this:  
news/sports/football/4  
and Rails would route to the article controller and show action with  
the following params: {“sections”=\>[“news”, “sports”, “football”],  
“article\_id”=\>“4”}  
Pretty cool, and hopefully this helps someone else with the same  
problem that I had.
