Forum: Ruby on Rails how to include an html file?

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.
39045f22049b1db3e3dd08c3bffac17e?d=identicon&s=25 Filip Godsmurf (godsmurf)
on 2006-02-21 20:25
I have a bunch of html files with partial page content. I'd like to be
able to include the content of these files in my RoR views without
having to change or rename them.

In PHP I'd simply use
  include("file.html");

What is the RoR equivalent of this? render_file insists on it being an
rhtml template, and render_partial requires me to rename the file.

Ideally, I could put the files in a separate dir, e.g. in /public/html/

Tia!
Cb610750ee94ca103aef4b2dc7b1b768?d=identicon&s=25 Nick Stuart (Guest)
on 2006-02-21 20:35
(Received via mailing list)
Easiest way is to simply rename them.

Other then that though you could simple open the file and spit the
results manually. So, a simple helper function:

def include_page(file_name)
  result = ""
  File.open(file_name, "r") { |f| result << f.read }
  result
end

*note, not tested for typos or accuracy :)

This should work, and you can add in a defualt directory to look in
and things to make it a little easier to work with.

-Nick
This topic is locked and can not be replied to.