Get Started with eRuby
Posted by on 10 August 2012 11:56 AM
Set Up Your cgi-bin Folder
You need to add an 'eruby' script to your '~/public_html/cgi-bin' folder. Here's what it should look like:
#!/bin/bash echo "Content-type: text/html" echo echo "<!DOCTYPE HTML>" erubis -E Stdout <$DOCUMENT_ROOT$REQUEST_URI
Save the above file as '~/public_html/cgi-bin/eruby' and change its permissions to be executable.
Set Up Your .htaccess File
Finally, you'll need to create an .htaccess file in your '~/public_html/' folder and add the following three lines:
Action eruby-script /cgi-bin/eruby AddHandler eruby-script .rhtml DirectoryIndex index.html index.rhtml
Set Up a Rewrite Rule
*This is an optional step.
If you don't like having a 'rhtml' hanging off the end of your URLs, you can add this to the .htaccess file as well:
RewriteRule ^(.*)(?<!\.rhtml)$ $1.rhtml [L]
Now you can upload files ending in '.rhtml' that contain Ruby code enclosed in <% %> or <%= %> markers and have the contents run as Ruby:
<html> <body> 1 and 2 is <% puts 1 + 2 %> </body> </html>