I’m sure this is a horror in dozens of ways, but eruby sucks and my host doesn’t have mod_ruby. So I got creative.
The .htaccess rewrites requests for any file ending in .rb to this handler.php, which confirms that the requested ruby script exists, then executes it and prints the result.
//PHP script to execute ruby scripts when the host doesn’t have a cgi handler for .rb
//Use with this .htaccess:
RewriteRule ^(.*)\.rb$ handler.php?rb=$1.rb [NC,QSA]
$file = $_GET[‘rb’];
foreach($_REQUEST as $key=>$value) if($key != ‘rb’) $args .= ” $key=”.urlencode($value);
echo ‘404- Page not found’;
Here’s an example ruby script using this hack- nothing special to do here at all:
print “Hello from Ruby!
print “All of the input variables:
ARGV.each do |arg|
All the GET, POST, and COOKIE variables are at your fingertips in ARGV! (You could get them with Ruby’s CGI module as well.)
So here’s what it looks like to users: