[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How to get erb to process .rhtml or .rtml files

Paul

5/29/2005 5:58:00 AM

Hi all,
found ruby 1.6 buried on my new web host's server & can get mysql4.1
access fine (now that is). I can get erb on this server to work via a
bit of trickery. The question I have is, how do I set up .htacces or
whatever the file is called to get apache to run this for me...

ruby16 erb.rb thefile.rtml

when a user clicks on the link with 'thefile.rtml' in it.

....so I can do all that embedded ruby stuff in thefile.rtml & present
the user with whateever I want.

The test files, test.rb, 0.rb and 1.rb that come with erb 1.4.3 work
for me.

The server doesn't or won't support mod_ruby or fastcgi.

I know there is an AddHandler statement but don't know how to use it
for this.

AddHandler rubypage .rhtml
AddHandler rubypage .rtml
Action rubypage /rubyrun.cgi?

The prior statements tell apache to run rubyrun.cgi for files ending in
..rhtml or .rtml. rubyrun.cgi (not tested) takes the file and pareses it
trough erb and displays the results in the browser.

rubyrun.cgi
#!usr/local/bin/ruby16 -Icgi-bin/ruby/lib/ruby/1.6
require 'erb/erb'
fh = File.new( ARGV[0] )
eruby_script = fh.read
erb = ERb.new(eruby_script)
print erb.result( binding )
^z

Whats the best way?

Any advide or thoughts.

Thank you Paul.

1 Answer

Paul

5/30/2005 5:02:00 AM

0

Got it working.

If anyone's interested here's the steps.

Added to .htaccess in /htdocs ....
AddHandler cgi-script .rb
Action application/x-httpd-ruby /usr/local/bin/ruby16?

AddHandler rubypage .rhtml .rtml
Action rubypage /erbrun.cgi?
.....


created erbrun.cgi, placed in /htdocs ....
#!/usr/local/bin/ruby16 -I/www/m/mysite/cgi-bin/ruby/lib/ruby/1.8
puts "Content-type: text/html\n\n"
require 'erb/erb'
fh = File.new( ENV['DOCUMENT_ROOT'] + ARGV[0] )
eruby_script = fh.read
erb = ERb.new(eruby_script)
print erb.result( binding )
..... placed in /htdocs


create try.rhtml & place on server somewhere ....
<html>
<head>
<title>eruby example</title>
</head>
<body>
<h1>Enumeration</h1>
<ul>
<%(1..10).each do|i|%>
<li>number <%=i%></li>
<%end%>
</ul>
<h1>Environment variables</h1>
<table>
<%ENV.keys.sort.each do |key|%>
<tr>
<th><%=key%></th><td><%=ENV[key]%></td>
</tr>
<%end%>
</table>
</body>
</html>
..... browse to www.mysite.com/somewhere/try.rhtml and it works .


create testruby.rb somewher on the server ....
#!/usr/local/bin/ruby16
puts "Content-type: text/html\n\n"
puts "<HTML><PRE>Test\n"
print `ls -alF /usr/local/lib/ruby/1.6/`
.....

testruby.rb also works from the browser.

:)