# RE: how to include an html file?

**URL:** <https://www.ruby-forum.com/t/re-how-to-include-an-html-file/71532>\
**Category:** Rails\
**Created:** [February 21, 2006, 8:38pm UTC](https://www.ruby-forum.com/t/re-how-to-include-an-html-file/71532 "2006-02-21T20:38:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [February 21, 2006, 8:38pm UTC](https://www.ruby-forum.com/t/re-how-to-include-an-html-file/71532/1 "2006-02-21T20:38:42Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [February 21, 2006, 8:54pm UTC](https://www.ruby-forum.com/t/re-how-to-include-an-html-file/71532/2 "2006-02-21T20:54:24Z")

</div>

Of course it can! 🙂  
Thanks for that, there seems to always be a ‘shorter’ way in ruby!

---

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [February 21, 2006, 9:01pm UTC](https://www.ruby-forum.com/t/re-how-to-include-an-html-file/71532/3 "2006-02-21T21:01:55Z")

</div>

Thanx guys!

---

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [February 22, 2006, 5:23am UTC](https://www.ruby-forum.com/t/re-how-to-include-an-html-file/71532/4 "2006-02-22T05:23:57Z")

</div>

OR:

\<%= render :file =\> ‘/absolute/full/path/to/file’ %\>

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

Cheers-  
-Ezra
