Ruby/Basic CGI3

From Meshplex

Jump to: navigation, search
Image:Ruby_on_rails_tutorials.jpg
Ruby for complete beginners
Ruby Introduction
What can I use RoR for?
Reasons for choosing RoR over other popular programming languages such as php or asp.net .What makes Ruby so much more special
Where can I find RoR? In what “forms” does it come?
How to install RoR.Solutions for both the novice and professional programmers on Windows,Mac OS X and Linux.Prerequisites.
Ruby programming tutorials for beginners:
Ruby Basics
Ruby Variables, Datatypes, Operators
Ruby Symbols
Ruby Statements
Ruby Converting data to another type: type conversion or typecasting
Ruby Arrays, Hashes, Ranges
Ruby Functions and built in functions
Ruby Control structures
Ruby Regular expressions and blocks
Ruby Loops
Ruby Recursion
Ruby Data Structures
Ruby Methods, Classes, Modules, Namespaces
Ruby Exceptions
Ruby Object Oriented Programming
Ruby Multithreading
Ruby File Handling.Input and Output
Ruby Basic GUI
Ruby and databases.Ruby on Rails and MySQL
Ruby Basic CGI.Using fastCGI
Ruby Basic Networking and web programming
Ruby Basic Graphics
Ajax and Rails.Web 2.0 and what it means
Ruby Testing, Debugging, Automation of tasks
Ruby Apache,Capistrano, Mongrel,lighttpd – reviews and tips
Finding a Ruby on Rails ready web hosting company
BONUS: mini tutorial for a simple RoR application
Basic CGI.Using fastCGI

Here's how you could implement a form for your site with CGI in Ruby:

require 'cgi'
cgi = CGI.new
cgi.params ! {"name"=>["Ruby programming language"],
"reason"=>["oop", "modern","activerecord","web 2.0"]}
cgi.params['name'] ! ["Ruby programming language"]
cgi.params['reason'] ! ["modern","activerecord","web 2.0"]
cgi.params['name'] = [ cgi['name'].upcase ]
cgi.params ! {"name"=>["Ruby programming language"],
"reason"=>["modern","activerecord","web 2.0"]}

And the html code:

<html>
<head><title>Ruby rocks</title></head>
<body>
I chose Ruby because:
<form target="cgibin/
reasons.rb">
<input type="checkbox" name="reason" value="oop" />
It's great oop capabilities<br />
<input type="checkbox" name="reason" value="modern" />
It's very modern<br />
<input type="checkbox" name="reason" value="activerecord" />
Rails and ActiveRecord exist<br />
<input type="checkbox" name="reason" value="web 2.0" />
It's very web 2.0
<input type="submit"/>
</form>
</body>
</html


FastCGI

"FastCGI is a language independent, scalable, open extension to CGI that provides high performance without the limitations of server specific APIs".There are some who recommend not pairing fastCGI and Ruby due to lack of real performance.

How to install:

curl -O http://www.fastcgi.com/dist/fcgi-2.4.0.tar.gz
tar xzvf fcgi-2.4.0.tar.gz
cd fcgi-2.4.0
./configure --prefix=/usr/local
make
sudo make install
cd ..

Add the Ruby-FastCGI bindings:

curl -O http://rubyforge.iasi.roedu.net/files/fcgi/ruby-fcgi-0.8.7.tar.gz
tar xzvf ruby-fcgi-0.8.7.tar.gz
cd ruby-fcgi-0.8.7
/usr/local/bin/ruby install.rb config --prefix=/usr/local
/usr/local/bin/ruby install.rb setup
sudo /usr/local/bin/ruby install.rb install
cd ..
sudo gem install fcgi

More web resources of fastCGI and Ruby:

http://blogs.codehaus.org/people/tirsen/archives/001041_ruby_on_rails_and_fastcgi_scaling_using_processes_instead_of_threads.html

http://blog.litespeedtech.com/articles/2006/08/31/why-i-dont-think-ruby-fcgi-can-beat-lsapi-benchmark-ruby-fcgi-vs-lsapi

http://www.crucialwebhost.com/blog/ruby-on-rails-fastcgi-fcgi-in-openbsd/

http://www.pigstye.net/articles/2006/09/21/install-ruby-rails-with-fastcgi-on-apache2

CGI can get pretty complex at some point and this short tutorial is *very* introductory, you will find plenty more advanced resources on the web if you're particularly interested in learning more about CGI in Ruby.

Previous
Personal tools
Interesting Sites
ListSergeant