Chapter 11. Simple CGI Forms

There are many ways to do CGI with Ruby. For small tasks, I have found that erb/eruby with the cgi module is the simplest, so that’s what I use for the rest of this section. The easiest way to get eruby working is to install mod_ruby (and you get a speed boost, to boot!) After mod_ruby is installed, you need to add some code to your Apache configuration to get it interpreting .rhtml files as eruby files.

<IfModule mod_ruby.c>
    RubyRequire apache/eruby-run

    <Files *.rhtml>
        SetHandler ruby-object
        RubyHandler Apache::ERubyRun.instance
    </Files>
</IfModule>

The preceding code causes Apache to use mod_ruby’s special ERubyRun mode to parse any .rhtml file. .rhtml files are similar to ASP or PHP in that they are normal HTML files ...

Get Ruby Phrasebook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.