ERB

eRuby is an implementation that allows embedding Ruby inside HTML or other document, similar to PHP. It comes in several implementations: eruby is in C and faster; ERB is cross-platform and ships with Ruby. Both can be used on Dreamhost.

Setup
Create this file as e.g. :

require "cgi" require "erb" cgi = CGI.new ENV['GEM_PATH'] = "#{ENV['GEM_PATH']}:/home/YOUR_NAME/.gems" require "rubygems" begin path = nil if (ENV['PATH_TRANSLATED']) path = ENV['PATH_TRANSLATED'] else file_path = ENV['REDIRECT_URL'].include?(File.basename(__FILE__)) ? ENV['SCRIPT_URL'] : ENV['REDIRECT_URL'] path = File.expand_path(ENV['DOCUMENT_ROOT'] + '/' + file_path) raise "Attempt to access invalid path: #{path}" unless path.index(ENV['DOCUMENT_ROOT']) == 0 end # So that working directory is not here but where the .rhtml is: Dir.chdir(File.dirname(path)) erb = File.open(path) { |f| ERB.new(f.read) } print cgi.header + erb.result(binding) rescue Exception print "Content-Type: text/html\n\n" if $DEBUG # print out more descriptive errors while debugging print "&lt;h1>Script Error&lt;/h1>" print "&lt;pre>#{ $! }&lt;/pre>" print "&lt;h2>Backtrace&lt;/h2>" print "&lt;pre>#{$!.backtrace.join("\n")}&lt;/pre>" print "&lt;h2>Environment&lt;/h2>" print "&lt;pre>#{ENV.keys.map { |key| key + ' = ' + ENV[key] + "\n"} }&lt;/pre>" else print "&lt;h1>ERB error&lt;/h1>&lt;p>#{ $! }&lt;/p>" end end
 * 1) !/usr/bin/env ruby
 * 2) run ruby using the --debug flag for more descriptive errors
 * 1) This cgi object is available in your RHTML files
 * 1) Optionally, enable using gems you've installed per http://forum.dreamhosters.com/programming/43221-gem-install-broken.htm#Post43228
 * 1) Optionally, require stuff here so you don't need to do this in each RHTML file

The file must be in a web-accessible directory.

Make it executable:

chmod +x erb.cgi

Create or edit, adding this:

DirectoryIndex index.rhtml index.php index.html index.htm AddHandler rubypage .rhtml Action rubypage /cgi-bin/erb.cgi
 * 1) If you want Apache to use index.rhtml in addition to index.php etc.

Test
Test it with a page like this, for example as. The extension must be.

<%= title = "Testing!" %>   &lt;h1><%= title %>&lt;/h1> &lt;p>GEM_PATH: <%= ENV['GEM_PATH'] %>&lt;/p> &lt;p>Params: <%= cgi.params.inspect %>&lt;/p>