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.
Jeroen H. (Guest)
on 2006-03-13 16: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
Norman T. (Guest)
on 2006-03-14 12:07
(Received via mailing list)
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
This topic is locked and can not be replied to.