O'Reilly logo

Ruby by Example by Kevin C. Baird

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

#41 A Simple CGI Script (simple_cgi.rb)

This script is fairly quick and dirty, but it shows the basics of how to use Ruby for CGI and introduces Ruby’s aptly named cgi library. You’ll need to put this script in your system’s cgi-bin directory. It’s /usr/lib/cgi-bin/ on my system, although your system’s location may be different. You can then browse to http://localhost/cgi-bin/simple_cgi.rb, because your webserver will provide access to the contents of your cgi-bin directory via http://localhost/cgi-bin/.

Note

You’ll also need to give simple_cgi.rb 755 permissions, meaning that its owner can do anything with it and everyone else can read and execute it, but not write (change) it. For more information, see man chmod.

Before we even get started with ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required