# Dynamic controller dispatching in rails 3

**URL:** <https://www.ruby-forum.com/t/dynamic-controller-dispatching-in-rails-3/195493>\
**Category:** Rails\
**Created:** [September 23, 2010, 9:21pm UTC](https://www.ruby-forum.com/t/dynamic-controller-dispatching-in-rails-3/195493 "2010-09-23T21:21:53Z")\
**Posts on this page:** 1\
**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 23, 2010, 9:21pm UTC](https://www.ruby-forum.com/t/dynamic-controller-dispatching-in-rails-3/195493/1 "2010-09-23T21:21:53Z")

</div>

Is there any offical way you could dynamically dispatch controllers in  
Rails 3?  
My goal is to invoke different controllers based on path segments like  
this:

/news/sport-blog, should map to a blog controller  
or  
/news/sports/2, should map to a page controler

In the example cases above, the path should be queried from a STI page  
model, and the type attribute should decide which controller to  
invoke.

psuedo code:  
match “\*path\_segments”, :to =\>  
“#{Page.find\_by\_path(params[:path\_segments]).type}#index”

The idea behind this is that it fits very nice in a cms system where  
informative url:s are important. I’ve looked at other cms systems  
built on Rails, many uses a single catch-all controller, but that  
forces you to write another dispatcher on your own.

Thanks in advance  
Fredrik Martenson
