# External html page include

**URL:** <https://www.ruby-forum.com/t/external-html-page-include/172318>\
**Category:** Ruby\
**Created:** [July 19, 2009, 3:43pm UTC](https://www.ruby-forum.com/t/external-html-page-include/172318 "2009-07-19T15:43:44Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![staypufd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecd19e/32.png) [@staypufd](https://www.ruby-forum.com/u/staypufd)\
**Post date:** [July 19, 2009, 3:43pm UTC](https://www.ruby-forum.com/t/external-html-page-include/172318/1 "2009-07-19T15:43:44Z")

</div>

I would like to include an external html page into a .rhtml document. I  
know you can do it with iframes but that is not what I want. Does ruby  
have an include tag for that?

---

<div class="post-metadata">

**Author:** ![staypufd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecd19e/32.png) [@staypufd](https://www.ruby-forum.com/u/staypufd)\
**Post date:** [July 19, 2009, 11:54pm UTC](https://www.ruby-forum.com/t/external-html-page-include/172318/2 "2009-07-19T23:54:27Z")

</div>

Sam G. wrote:

> I would like to include an external html page into a .rhtml document. I  
> know you can do it with iframes but that is not what I want. Does ruby  
> have an include tag for that?

Who cares what ruby has? The generated page is html. If you can’t do  
it with the available html tags, e.g. frames or iframes, then ruby isn’t  
going to magically be able to help you.

It sounds like you are trying to get ruby to enter into a conspiracy  
with you to steal content.

---

<div class="post-metadata">

**Author:** ![staypufd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecd19e/32.png) [@staypufd](https://www.ruby-forum.com/u/staypufd)\
**Post date:** [July 19, 2009, 11:59pm UTC](https://www.ruby-forum.com/t/external-html-page-include/172318/3 "2009-07-19T23:59:20Z")

</div>

Sam G. wrote:

> I would like to include an external html page into a .rhtml document. I  
> know you can do it with iframes but that is not what I want. Does ruby  
> have an include tag for that?

On the other hand, if you are trying to incorporate some raw html into a  
.rhtml page, just read the file and output it:

\<%= %\> # executes the Ruby code and displays the result

---

<div class="post-metadata">

**Author:** ![staypufd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecd19e/32.png) [@staypufd](https://www.ruby-forum.com/u/staypufd)\
**Post date:** [July 20, 2009, 12:47am UTC](https://www.ruby-forum.com/t/external-html-page-include/172318/4 "2009-07-20T00:47:56Z")

</div>

Sam G. wrote:

> How? with a File.Open()?. I’m new to ruby so I’m not sure if that is  
> what I should do.

You could write:

f = File.open(“page.htm”)  
f.read()

or you could combine that into one line:

File.open(“page.htm”).read()

or you could use the shortcut:

IO.read(“page.htm”)

---

<div class="post-metadata">

**Author:** ![staypufd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecd19e/32.png) [@staypufd](https://www.ruby-forum.com/u/staypufd)\
**Post date:** [July 20, 2009, 12:27am UTC](https://www.ruby-forum.com/t/external-html-page-include/172318/5 "2009-07-20T00:27:58Z")

</div>

How? with a File.Open()?. I’m new to ruby so I’m not sure if that is  
what I should do.

7stud – wrote:

> Sam G. wrote:
> 
> > I would like to include an external html page into a .rhtml document. I  
> > know you can do it with iframes but that is not what I want. Does ruby  
> > have an include tag for that?
> 
> On the other hand, if you are trying to incorporate some raw html into a  
> .rhtml page, just read the file and output it:
> 
> \<%= %\> # executes the Ruby code and displays the result

---

<div class="post-metadata">

**Author:** ![staypufd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecd19e/32.png) [@staypufd](https://www.ruby-forum.com/u/staypufd)\
**Post date:** [July 20, 2009, 1:13am UTC](https://www.ruby-forum.com/t/external-html-page-include/172318/6 "2009-07-20T01:13:13Z")

</div>

That is what I thought and it aint working. I’m trying to open a file on  
another server i:e [http://docs.google.com/View?id=10](http://docs.google.com/View?id=10). So I guess iframe  
is the only option

7stud – wrote:

> Sam G. wrote:
> 
> > How? with a File.Open()?. I’m new to ruby so I’m not sure if that is  
> > what I should do.
> 
> You could write:
> 
> f = File.open(“page.htm”)  
> f.read()
> 
> or you could combine that into one line:
> 
> File.open(“page.htm”).read()
> 
> or you could use the shortcut:
> 
> IO.read(“page.htm”)

---

<div class="post-metadata">

**Author:** ![staypufd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecd19e/32.png) [@staypufd](https://www.ruby-forum.com/u/staypufd)\
**Post date:** [July 20, 2009, 1:52am UTC](https://www.ruby-forum.com/t/external-html-page-include/172318/7 "2009-07-20T01:52:02Z")

</div>

Didn’t look closely enough at what’s going on here.

What exactly are you trying to do? The previous response should work.

However, if you are actually requesting a page from something like  
Google  
Docs, you need to realize that the request will be made at the server,  
not  
in the browser, so your cookies will not be in the request, so you will  
not  
be authenticated unless you explicitly do that. It is more trouble than  
it’s  
worth in most cases.

Additionally, unless you intend to alter the HTML in some way before  
including it in the page, it will look all off, so probably best to  
stick  
with iFrames unless it is absolutely necessary to scrape (which is what  
you  
are doing)

-chris

---

<div class="post-metadata">

**Author:** ![staypufd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecd19e/32.png) [@staypufd](https://www.ruby-forum.com/u/staypufd)\
**Post date:** [July 20, 2009, 1:49am UTC](https://www.ruby-forum.com/t/external-html-page-include/172318/8 "2009-07-20T01:49:42Z")

</div>

You should use something like  
require ‘open-uri’

puts open(‘[http://some-url.com/file](http://some-url.com/file)’).read

or the curl libraries.

Chris R.  
Chief Developer - (ph)Pea  
Co-Founder - Invalid Media

---

<div class="post-metadata">

**Author:** ![staypufd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecd19e/32.png) [@staypufd](https://www.ruby-forum.com/u/staypufd)\
**Post date:** [July 20, 2009, 5:26am UTC](https://www.ruby-forum.com/t/external-html-page-include/172318/9 "2009-07-20T05:26:37Z")

</div>

You’re right. I’ll stick with iframes.

thanks anyway

Chris R. wrote:

> Didn’t look closely enough at what’s going on here.
> 
> What exactly are you trying to do? The previous response should work.
> 
> However, if you are actually requesting a page from something like  
> Google  
> Docs, you need to realize that the request will be made at the server,  
> not  
> in the browser, so your cookies will not be in the request, so you will  
> not  
> be authenticated unless you explicitly do that. It is more trouble than  
> it’s  
> worth in most cases.
> 
> Additionally, unless you intend to alter the HTML in some way before  
> including it in the page, it will look all off, so probably best to  
> stick  
> with iFrames unless it is absolutely necessary to scrape (which is what  
> you  
> are doing)
> 
> -chris
