Forum: Ruby on Rails rendering templates outside defaultl views location

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B9a732fc30c32098347a0177c75ee27b?d=identicon&s=25 Jeroen Houben (Guest)
on 2006-03-13 15:26
(Received via mailing list)
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
Bf66e10c8fc4abefebde0425e7f6f15a?d=identicon&s=25 Norman Timmler (Guest)
on 2006-03-14 11:07
(Received via mailing list)
Am Montag, den 13.03.2006, 15:18 +0100 schrieb Jeroen Houben:
> 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 Timmler

http://blog.inlet-media.de
This topic is locked and can not be replied to.