# How to make views changable

**URL:** <https://www.ruby-forum.com/t/how-to-make-views-changable/58932>\
**Category:** Rails\
**Created:** [April 27, 2006, 8:07am UTC](https://www.ruby-forum.com/t/how-to-make-views-changable/58932 "2006-04-27T08:07:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kostya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/d2c977/32.png) [@Kostya](https://www.ruby-forum.com/u/Kostya)\
**Post date:** [April 27, 2006, 8:07am UTC](https://www.ruby-forum.com/t/how-to-make-views-changable/58932/1 "2006-04-27T08:07:11Z")

</div>

Hello

I need to make site views changeable  
I found how to change layouts but it is not enough, becouse templates  
can use different ways to display and organize content.  
I found one way to do this, but i need to make subfolders in my  
‘view/layouts’, ‘view/controller\_name’ both and to create additional  
subfolder somewhere in ‘public’ to put there tepmlate images, styles, js  
etc.

Is there any options to tell rails to look for views in the other  
places, not in ‘app/view’ ?

---

<div class="post-metadata">

**Author:** ![Kostya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/d2c977/32.png) [@Kostya](https://www.ruby-forum.com/u/Kostya)\
**Post date:** [April 27, 2006, 8:27am UTC](https://www.ruby-forum.com/t/how-to-make-views-changable/58932/2 "2006-04-27T08:27:46Z")

</div>

why not put images, styles and js in the appropriate folders that exist  
already? (Except the images one… you would need to create that one)

---

<div class="post-metadata">

**Author:** ![Kostya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/d2c977/32.png) [@Kostya](https://www.ruby-forum.com/u/Kostya)\
**Post date:** [April 27, 2006, 8:41am UTC](https://www.ruby-forum.com/t/how-to-make-views-changable/58932/3 "2006-04-27T08:41:44Z")

</div>

the problem is not in place for images  
i just want to have all files related to some template in one folder  
maximum 2 folders  
1 - for views and layouts  
2 - public folder for images and other browsable things

in php whith smarty it would be something like that  
$smarty-\>templates\_dir = “/path/to/my/templates”  
so  
$smarty-\>display(“index.tpl”)  
will render  
/path/to/my/templates/index.tpl

but rails somehow knows that all views are in /rails/app/view  
is it passible to change this path inside the controller dinamicly ?

---

<div class="post-metadata">

**Author:** ![Kostya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/d2c977/32.png) [@Kostya](https://www.ruby-forum.com/u/Kostya)\
**Post date:** [April 27, 2006, 11:08am UTC](https://www.ruby-forum.com/t/how-to-make-views-changable/58932/4 "2006-04-27T11:08:48Z")

</div>

On Apr 27, 2006, at 1:46 AM, Åukasz Piestrzeniewicz wrote:

> > $smarty-\>display(“index.tpl”)  
> > will render  
> > /path/to/my/templates/index.tpl
> > 
> > but rails somehow knows that all views are in /rails/app/view  
> > is it passible to change this path inside the controller dinamicly ?
> 
> It’s quite simple. In your controller just put:
> 
> @response.template.base\_path = “/absolute/path/to/template/root”

Please don’t do that!

At the very least, make a CONSTANT in config/environment.rb and  
use that rather than a string somewhere in your source code.

Better yet, figure out a way to handle it relative to RAILS\_ROOT  
so that if you move your app around in the filesystem, it will  
still work.

–  
– Tom M.

---

<div class="post-metadata">

**Author:** ![Kostya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/d2c977/32.png) [@Kostya](https://www.ruby-forum.com/u/Kostya)\
**Post date:** [April 27, 2006, 10:46am UTC](https://www.ruby-forum.com/t/how-to-make-views-changable/58932/5 "2006-04-27T10:46:56Z")

</div>

Kostya wrote:

> the problem is not in place for images  
> i just want to have all files related to some template in one folder  
> maximum 2 folders  
> 1 - for views and layouts  
> 2 - public folder for images and other browsable things
> 
> in php whith smarty it would be something like that  
> $smarty-\>templates\_dir = “/path/to/my/templates”  
> so  
> $smarty-\>display(“index.tpl”)  
> will render  
> /path/to/my/templates/index.tpl
> 
> but rails somehow knows that all views are in /rails/app/view  
> is it passible to change this path inside the controller dinamicly ?

It’s quite simple. In your controller just put:

@response.template.base\_path = “/absolute/path/to/template/root”  
render(:action =\> ‘index’)

(see:  
[http://ragnarson.blogspot.com/2006/04/dynamic-templateroot-revisited.html](http://ragnarson.blogspot.com/2006/04/dynamic-templateroot-revisited.html)  
and [http://ragnarson.blogspot.com/2006/03/dynamic-templateroot.html](http://ragnarson.blogspot.com/2006/03/dynamic-templateroot.html))

But do not be tempted to put everything (templates, images) in one  
place. It is a very bad decission. Rather get used to current setup.

Remember, that generated html code should be strictly semantical and  
site look should be defined by CSS. In that sense html is completly  
unrelated to visual effect (see [http://csszengarden.com](http://csszengarden.com) for examples).

Cheers,  
Åukasz
