Forum: Ruby on Rails Rendering partials from outside of Rails

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
11e31c35272655b121aa9f8e14d62566?d=identicon&s=25 Jeff (Guest)
on 2009-01-01 23:33
(Received via mailing list)
I have a client Rails project, and I'd like to create a folder outside
of the Rails app completely. The client could create vanilla HTML
files and drop them into the folder. I'd then like to render those
HTML files as partials against the main site template. I want to keep
the client as far from the actual Rails app as possible. Is there a
way for me to render partials from outside the Rails root? Or at least
outside views?

97f7778bd994b7e4c5ad025be0640bde?d=identicon&s=25 Andrius Chamentauskas (Guest)
on 2009-01-02 12:43
(Received via mailing list)
render :file => ...
11e31c35272655b121aa9f8e14d62566?d=identicon&s=25 Jeff (Guest)
on 2009-01-02 19:39
(Received via mailing list)
I'm using render :file, but as far as I can tell, Rails still tacks
RAILS_ROOT/app/views to the beginning of the given filename. Is there
a way to disable this? Ideally, I'd be rendering the partial from
outside the Rails root entirely.
10f7e00c1c5c60e2173995eb16f4ffc7?d=identicon&s=25 pepe (Guest)
on 2009-01-03 18:59
(Received via mailing list)
From the API:

File rendering works just like action rendering except that it takes a
filesystem path. By default, the path is assumed to be absolute, and
the current layout is not applied.

  # Renders the template located at the absolute filesystem path
  render :file => "/path/to/some/template.erb"
  render :file => "c:/path/to/some/template.erb"

  # Renders a template within the current layout, and with a 404
status code
  render :file => "/path/to/some/template.erb", :layout =>
true, :status => 404
  render :file => "c:/path/to/some/template.erb", :layout =>
true, :status => 404

Based on that you should be able to use one of the 2 first samples and
modify it for your needs.

11e31c35272655b121aa9f8e14d62566?d=identicon&s=25 Jeff (Guest)
on 2009-01-05 03:28
(Received via mailing list)
Thanks for the help on this. I figured out what my problem was.

render :partial works as advertised when used in a controller, but not
as a helper when used in a view (at least in Rails 2.0.2). The helper
version of render tries to tack the view path to the beginning of the
filepath no matter what. Instead, I used render_to_string form the
controller and used the string directly in the view. This may have
been fixed in a subsequent version of Rails.
This topic is locked and can not be replied to.