# How to define template\_root in controller?

**URL:** <https://www.ruby-forum.com/t/how-to-define-template-root-in-controller/104753>\
**Category:** Rails\
**Created:** [May 22, 2007, 4:59am UTC](https://www.ruby-forum.com/t/how-to-define-template-root-in-controller/104753 "2007-05-22T04:59:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rmehta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ea666f/32.png) [@rmehta](https://www.ruby-forum.com/u/rmehta)\
**Post date:** [May 22, 2007, 4:59am UTC](https://www.ruby-forum.com/t/how-to-define-template-root-in-controller/104753/1 "2007-05-22T04:59:25Z")

</div>

Hi,

Based on the if the user is logged to site A or site B, with the single  
codebase I have to show different views. What I mean is even though the  
contents on both sites for a view will be same but the look and feel  
will be different. So, I am planning to have a directory structure like  
this

```
/app/views/reports
|
|
  -siteA
   |
   |
    -scr1
    -scr2
     .
     .
  -siteB
   |
   |
    -scr1
    -scr2
      .
      .

```

Reports controller will have all the methods for the scr1 & scr2. But  
based on the site info (which I have in session), how can I set the view  
root for the controller? I can check in each method and can use

render :template=\>‘siteA/scr1’

or render :template=\>‘siteB/scr1’

But is there a way to do it one time for the whole controller and not do  
it with each render?

Thanks for any help.

---

<div class="post-metadata">

**Author:** ![rmehta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ea666f/32.png) [@rmehta](https://www.ruby-forum.com/u/rmehta)\
**Post date:** [May 22, 2007, 5:47am UTC](https://www.ruby-forum.com/t/how-to-define-template-root-in-controller/104753/2 "2007-05-22T05:47:53Z")

</div>

I have implemented this with a patched version of the theme\_support  
plugin by Matt McCray. There is a patch floating around that makes it  
compatible with Rails 1.2 (the official version is only compatible  
with 1.1). I have submitted some patches to Matt, but he seems to be  
AWOL.

Rails 2.0 will support the notion of view paths which will make the  
whole process work a lot smoother ([http://weblog.rubyonrails.org/](http://weblog.rubyonrails.org/)  
2007/2/4/new-feature-for-rails-2-0-multiple-controller-view-paths).

I’m currently in the process of deploying a major site using this  
feature and I’ve got a writeup in the works about how I set it all  
up. Should be posted in the next week some time in my blog at  
[http://darwinweb.net/](http://darwinweb.net/). I might even fork theme\_support and release a  
plugin focused around multiple domain applications.
