# CMS - how to associate "pages" with controllers and routes

**URL:** <https://www.ruby-forum.com/t/cms-how-to-associate-pages-with-controllers-and-routes/125932>\
**Category:** Rails\
**Created:** [January 13, 2008, 11:05pm UTC](https://www.ruby-forum.com/t/cms-how-to-associate-pages-with-controllers-and-routes/125932 "2008-01-13T23:05:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![goodieboy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ecc23a/32.png) [@goodieboy](https://www.ruby-forum.com/u/goodieboy)\
**Post date:** [January 13, 2008, 11:05pm UTC](https://www.ruby-forum.com/t/cms-how-to-associate-pages-with-controllers-and-routes/125932/1 "2008-01-13T23:05:03Z")

</div>

Hi,

I’ve developed a simple CMS. I want to be able to create re-usable  
applications. One of them, a simple PayPal shop. In the backend, you  
can add “pages”. Very simple, a “code” and the “body”. The “code” is  
use as the identifier (about, about/me etc.). I’ve been mapping all  
(public) pages to a DefaultController. Th DefaultController looks at  
the PATH\_INFO string and determines which “page” to get. It then  
simply:

render :text=\>page.body

No problem.

Now, I have to somehow setup the e-commerce application. I have one  
client that wants to call the url “collection” and another that wants  
to call it “shop”. My thought was to add a few more fields to the page  
models; :handler and :action. Before the DefaultController renders the  
page, it would check to see if it had a handler associated with it and  
then include it (include MyPageHandler) to bring it into the scope of  
a controller. Actually, I did this and it seems to work.

But what happens when the user creates a page with a code of  
“collection/item”. On that page I guess you’d set the handler to  
ShopHandler and the action to “item”. But how does the  
ShopHandler.item method get the id of the product without parsing the  
URL (PATH\_INFO)? Because this stuff 'aint gonna be found in the  
routes. Unless… someone knows of a way?

What about looping through all of my pages in the routes.rb file and  
setting them that way?

My worries:

1. is there a better way?
2. what about routes? Can I do this without creating my own url  
parsing code?
3. time

I’m really under the gun to get this thing done, so if anyone has done  
anything like this before, I’d be so grateful to get a tip or two.

Thanks,  
Matt
