CGI Output

Use Ruby as a scripting language for your website.

Ruby Scripts

Hello World


With it's powerful features, syntax, and more, Ruby can even replace old web programming languages such as Perl and PHP.


First, in any cgi/web application, you must first send the correct headers to the browser. If the browser (your user/websurfer's internet program) gets the correct headers, then it will know how to display your page. 99% of all your programs will start sending data back with this one line:

puts "Content-type: text/html\n\n"

This line tells the browser that you are sending it a text-based HTML file, which is what most of the web uses these days. Other options might be images, for example, if your program does something with image files.


After that, you will want to start sending your HTML file, however interpreted by your program. Here's a really simple example:

puts "Content-type: text/html\n\n"

puts <<END
Welcome to my simple little Ruby website.<br />
Hello World!