# Rendering templates outside defaultl views location

**URL:** <https://www.ruby-forum.com/t/rendering-templates-outside-defaultl-views-location/80373>\
**Category:** Rails\
**Created:** [March 13, 2006, 3:26pm UTC](https://www.ruby-forum.com/t/rendering-templates-outside-defaultl-views-location/80373 "2006-03-13T15:26:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeroen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bbe5ce/32.png) [@jeroen](https://www.ruby-forum.com/u/jeroen)\
**Post date:** [March 13, 2006, 3:26pm UTC](https://www.ruby-forum.com/t/rendering-templates-outside-defaultl-views-location/80373/1 "2006-03-13T15:26:43Z")

</div>

Hi,

I’d like to accomplish the following situation (pseudo code):

IF file /path/to/some/tpldit exists  
render that  
ELSE  
render file from default tpl dir  
END

Should I override some built-in Rails methods for this or is there an  
easier (yet clean and DRY) way of doing this?

I’ve done something similar for the assetTagHelper related functions  
using a tiny plugin that overrides some built-in Rails methods, but I’d  
like to avoid that if I can.

TIA,

Jeroen

---

<div class="post-metadata">

**Author:** ![jeroen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bbe5ce/32.png) [@jeroen](https://www.ruby-forum.com/u/jeroen)\
**Post date:** [March 14, 2006, 11:07am UTC](https://www.ruby-forum.com/t/rendering-templates-outside-defaultl-views-location/80373/2 "2006-03-14T11:07:12Z")

</div>

Am Montag, den 13.03.2006, 15:18 +0100 schrieb Jeroen H.:

> Should I override some built-in Rails methods for this or is there an  
> easier (yet clean and DRY) way of doing this?
> 
> I’ve done something similar for the assetTagHelper related functions  
> using a tiny plugin that overrides some built-in Rails methods, but I’d  
> like to avoid that if I can.

def my\_action

# action code goes here

render ‘/path/to/some/tpldit’ if File.file?(‘/path/to/some/tpldit’)  
end

Unless the specific file is existent, the action method ends and the  
default view gets rendered. Pretty clean, isn’t it?

## If this is a general logic in your application - maybe you have two template directories, that mostly contain both my\_action.rhtml files, but some not - you should overwrite the render or template find method.

Norman T.

[http://blog.inlet-media.de](http://blog.inlet-media.de)
