|
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.
|