.rhtml from .cgi


#1

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? :slight_smile:

Psyche


#2

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


#3

Erm, of course you also would need a

require ‘erb’

In there somewhere.


#4

(…)
require ‘erb’
In there somewhere.

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

Have a nice weekend :slight_smile:
Mirek