Forum: Ruby .rhtml from .cgi

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.
Mirek R. (Guest)
on 2006-04-29 17:26
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
Mike F. (Guest)
on 2006-04-29 18:47
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
Mike F. (Guest)
on 2006-04-29 18:49
Erm, of course you also would need a

require 'erb'

In there somewhere.
Mirek R. (Guest)
on 2006-04-29 19:34
> (...)
> require 'erb'
> In there somewhere.

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

Have a nice weekend :)
Mirek
This topic is locked and can not be replied to.