# How to Prefixing a controller path in a route

**URL:** <https://www.ruby-forum.com/t/how-to-prefixing-a-controller-path-in-a-route/124333>\
**Category:** Rails\
**Created:** [December 27, 2007, 6:54pm UTC](https://www.ruby-forum.com/t/how-to-prefixing-a-controller-path-in-a-route/124333 "2007-12-27T18:54:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnlester](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@johnlester](https://www.ruby-forum.com/u/johnlester)\
**Post date:** [December 27, 2007, 6:54pm UTC](https://www.ruby-forum.com/t/how-to-prefixing-a-controller-path-in-a-route/124333/1 "2007-12-27T18:54:22Z")

</div>

Hi, I’ve been playing with routes and with Jamis B.'s plugin for host  
based routing ([http://svn.jamisbuck.org/rails-plugins/routing\_tricks/](http://svn.jamisbuck.org/rails-plugins/routing_tricks/)).

Here’s what I have in routes.rb:

1 map.connect ‘’, :conditions =\> { :host =\>  
/www.example.([com|co.uk](http://com%7Cco.uk))/ },  
2 :controller =\> “example/portal”  
3  
4 map.connect ‘:controller/:action/:id’,  
5 :conditions =\> { :host =\>  
/www.example.([com|co.uk](http://com%7Cco.uk))/ },  
6 :controller =\> “example/:controller”  
7  
8 # Default root  
9 map.connect ‘’, :controller =\> “portal”  
0  
1 # Install the default route as the lowest priority.  
2 map.connect ‘:controller/:action/:id.:format’  
3 map.connect ‘:controller/:action/:id’  
4

The first route at lines 1-2 fires on a request from  
“[http://www.example.com](http://www.example.com)”, causing the file  
“controllers/example/portal\_controller.rb” to be used.

Any other domain is picked up by line 13 and causes  
controllers/portal\_controller.rb" to be used.

The second route at lines 4-6 is supposed to fire on requests like  
“[http://www.example.com/portal](http://www.example.com/portal)” but all I get here is  
“controllers/portal\_controller.rb” being used (I suspect this is via the  
route at line 13).

I need my route at line 4-6 to respond to requests for  
"[http://www.example.com/controller/action/id](http://www.example.com/controller/action/id) and fire  
“controllers/example/controller” ?

I am pretty sure the code on line 6 is wrong but have no idea what it  
should be to make this work.

I want to handle overlays for several different domains.

Many thanks.

---

<div class="post-metadata">

**Author:** ![johnlester](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@johnlester](https://www.ruby-forum.com/u/johnlester)\
**Post date:** [December 27, 2007, 7:09pm UTC](https://www.ruby-forum.com/t/how-to-prefixing-a-controller-path-in-a-route/124333/2 "2007-12-27T19:09:06Z")

</div>

As a further clarification, the following works for  
[http://www.example/com/xyz](http://www.example/com/xyz) :

map.connect ‘xyz/:action/:id’,  
:conditions =\> { :host =\> /www.example.([com|co.uk](http://com%7Cco.uk))/  
},  
:controller =\> “example/xyz”

I want to do the below, but it does not work:

map.connect ‘:controller/:action/:id’,  
:conditions =\> { :host =\> /www.example.([com|co.uk](http://com%7Cco.uk))/  
},  
:controller =\> “example/:controller”

Any help greatly appreciated 🙂
