# .rhtml from .cgi

**URL:** <https://www.ruby-forum.com/t/rhtml-from-cgi/59164>\
**Category:** Ruby\
**Created:** [April 29, 2006, 3:26pm UTC](https://www.ruby-forum.com/t/rhtml-from-cgi/59164 "2006-04-29T15:26:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![psyche](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/848f3c/32.png) [@psyche](https://www.ruby-forum.com/u/psyche)\
**Post date:** [April 29, 2006, 3:26pm UTC](https://www.ruby-forum.com/t/rhtml-from-cgi/59164/1 "2006-04-29T15:26:06Z")

</div>

Greetz!

How to render .rhtml page from a Ruby .cgi file?  
I mean, there are:

## — index.cgi — #!/usr/bin/ruby puts “Content-type: text/html\n” WHAT\_GOES\_HERE? ‘mypage.rhtml’

and:

## — mypage.rhtml — The time is: \<%=Time.now%\>

Is it just sleepless night or what?  
How to make it work? 🙂

Psyche

---

<div class="post-metadata">

**Author:** ![psyche](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/848f3c/32.png) [@psyche](https://www.ruby-forum.com/u/psyche)\
**Post date:** [April 29, 2006, 4:47pm UTC](https://www.ruby-forum.com/t/rhtml-from-cgi/59164/2 "2006-04-29T16:47:54Z")

</div>

Mirek Rusin wrote:

> Greetz!
> 
> How to render .rhtml page from a Ruby .cgi file?  
> I mean, there are:
> 
> ## — index.cgi — #!/usr/bin/ruby puts “Content-type: text/html\n” WHAT\_GOES\_HERE? ‘mypage.rhtml’

template = File.open( “mypage.rhtml”, “r” ) { |f| f.read }  
mypage = ERb.new( template )  
result = mypage.result  
puts result

See: [http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/index.html](http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/index.html)

---

<div class="post-metadata">

**Author:** ![psyche](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/848f3c/32.png) [@psyche](https://www.ruby-forum.com/u/psyche)\
**Post date:** [April 29, 2006, 4:49pm UTC](https://www.ruby-forum.com/t/rhtml-from-cgi/59164/3 "2006-04-29T16:49:04Z")

</div>

Erm, of course you also would need a

require ‘erb’

In there somewhere.

---

<div class="post-metadata">

**Author:** ![psyche](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/848f3c/32.png) [@psyche](https://www.ruby-forum.com/u/psyche)\
**Post date:** [April 29, 2006, 5:34pm UTC](https://www.ruby-forum.com/t/rhtml-from-cgi/59164/4 "2006-04-29T17:34:32Z")

</div>

> (…)  
> require ‘erb’  
> In there somewhere.

Of course! Thank you Mike, that’s exactly what I was looking for.

Have a nice weekend 🙂  
Mirek
