Forum: Ruby on Rails RE: 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.
Berger, Daniel (Guest)
on 2006-02-21 21:38
(Received via mailing list)
> 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

That can be shortened to:

def include_page(file_name)
   IO.read(file_name)
end

Regards,

Dan
Nick S. (Guest)
on 2006-02-21 21:54
(Received via mailing list)
Of course it can! :)
Thanks for that, there seems to always be a 'shorter' way in ruby!
Filip G. (Guest)
on 2006-02-21 22:01
Thanx guys!
Ezra Z. (Guest)
on 2006-02-22 06:23
(Received via mailing list)
OR:

<%= render :file => '/absolute/full/path/to/file' %>

And that will interpret any erb thats in the file as well.

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