You can set up an Apache Web server to automatically parse
Ruby-embedded documents using eRuby, much in the same way that PHP
does. You create Ruby-embedded files with an ``
.rhtml
'' suffix
and configure the Web server to run the
eruby
executable on these
documents to produce the desired HTML output.
In order to use
eruby
with the Apache Web server, you need to
perform the following steps.
- Copy the
eruby
binary to the cgi-bin
directory.
- Add the following two lines to
httpd.conf
:
AddType application/x-httpd-eruby .rhtml
Action application/x-httpd-eruby /cgi-bin/eruby
|
- If desired, you can also add or replace the
DirectoryIndex
directive such that it includes index.rhtml
. This lets you use
Ruby to create directory listings for directories that do not
contain an index.html
. For instance, the following directive
would cause the embedded Ruby script index.rhtml
to be searched
for and served if neither index.html
nor index.shtml
existed in a
directory.
DirectoryIndex index.html index.shtml index.rhtml
|
Of course, you could also simply use a site-wide Ruby script as
well.
DirectoryIndex index.html index.shtml /cgi-bin/index.rb
|
And that's it! You can now write HTML documents that contain embedded
Ruby to generate forms and content dynamically. Be sure to see also
the Ruby
CGI
library, which is documented
beginning on page 497.