Knowledgebase: Ruby on Rails
Get Started with eRuby
Posted by on 16 December 2013 01:07 PM

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/sh 
echo 'Content-type: text.html'
echo ''
exec /usr/local/bin/erb /home/`whoami`/public_html/${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 

This will cause any *.rhtml files to load the eRuby script that we just set up, and that file will send the 'rhtml' file through the eRuby parser before displaying it to the user.

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:

RewriteEngine on
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
<%= 1 + 2 %>
</body>
</html>

If you are receiving a 404 (not found) error after setting this up you may need cgi privileges enabled on your account. You can open a support ticket and we will be happy to enable this for you.
(0 vote(s))
This article was helpful
This article was not helpful

Comments (0)
Post a new comment
 
 
Full Name:
Email:
Comments:
Help Desk Software by Kayako fusion