| By Seema Alevoor and Marina Sum, January 30, 2007, updated: February 27, 2008 |
Ruby on Rails (henceforth, RoR) is an open-source project in the Ruby interpreted scripting language with the goal of delivering a framework for efficiently developing Web applications. Sun Java System Web Server 7.0 (henceforth, Web Server 7.0), the latest Web server release from Sun, bundles FastCGI, an extension to the Common Gateway Interface (CGI), for scripting environments such as RoR. In addition, Web Server 7.0 offers many robust capabilities, including support for the Solaris 64-bit platform and cluster management as well as integration with Sun IDEs.
This article first describes how to install the Ruby language; RubyGems, the project for the standard that creates and manages libraries; Ruby on Rails; and the FastCGI Ruby gem. A gem is a packaged Ruby application or library. Later in the article, you learn how to create an RoR application and configure Web Server 7.0 to run RoR.
Note the following:
| - | Installing Ruby, RubyGems, and Rails |
| - | Creating a HelloWorld RoR Application |
| - | Configuring Web Server 7.0 |
| - | Conclusion |
| - | References |
The installations for Ruby, Ruby Gems, and Rails copy the executables to the /usr/local/bin directory. For easy execution, add that path to your PATH variable.
Note: If you cannot write to the /usr/local/bin directory, become root before starting the installation process.
Installing Ruby
To install Ruby:
/ruby. % cd /ruby/ruby-1.8.4
% ./configure
% make
% make install gcc but encounter compile-time errors, delete the gcc directory from your PATH variable and switch to one of the Sun Studio compilers.Installing RubyGems
To install RubyGems:
/ruby. % cd /ruby/rubygems-0.9.0
% export DLN_LIBRARY_PATH=/ruby/ruby-1.8.4/.ext/sparc-solaris2.10
% export RUBYLIB=/ruby/ruby-1.8.4/ext:/ruby/ruby-1.8.4/lib:/ruby-1.8.4:/ruby/ruby-1.8.4/.ext/sparc-solaris2.10
% ruby setup.rb --rbconfig=/ruby/ruby-1.8.4/rbconfig.rb Installing Rails
To install Ruby on Rails:
% export http_proxy=http:// proxy_hostname : proxy_portnumber % gem install rails --include-dependenciesInstalling FastCGI Ruby Gem
FastCGI offers a more efficient way than CGI for Web servers to call applications. To install the FastCGI Ruby gem:
/ruby. /fcgi-2.4.0 directory. % cd /ruby
% gem install fcgi -- --with-fcgi-include=/fcgi-2.4.0/include --with-fcgi-lib=/fcgi-2.4.0/libfcgi/.libs To create a Hello World application in RoR:
% mkdir /ruby/samples
% cd /ruby/samples
% rails hello-world
% cd hello-world
% ruby script/generate controller hello index.rhtml in the app/views/hello directory with the following one-line content: Hello! |
% ruby script/server http://localhost:3000/hello on your browser. Hello!, is displayed.Next, add some substance to the application:
controllers directory. Type: % cd /ruby/samples/hello-world/app/controllers hello_controller.rb file, add the following three boldfaced lines.
class HelloController < ApplicationController
def sayhello render_text "Hello! This is a simple example." end
end
|
% ruby script/server sayhello, at http://localhost:3000/hello/sayhello. Hello! This is a simple application. To configure Web Server 7.0:
magnus.conf file to load the FastCGI plug-in that is bundled with Web Server 7.0: Init fn="load-modules" shlib="libfastcgi.so" shlib_flags="(global|now)" |
obj.conf file.
<Object name="default">
...
...
#
# Pass requests for /dispatch.fcgi to rubyTest object.
#
NameTrans fn="assign-name" from="/dispatch.fcgi/*" name="rubyTest"
#
# Prefix /dispatch.fcgi/ to the original URI, which does not contain dispatch.fcgi, and
resend the request.
#
<If $uri !~ '^/dispatch.fcgi/.*'
and $uri !~ '^/stylesheets/*'
and $uri !~ '^/javascripts/*'>
<If defined $query>
NameTrans fn="restart" uri="/dispatch.fcgi$uri?$query"
</If>
<Else>
NameTrans fn="restart" uri="/dispatch.fcgi$uri"
</Else>
</If>
#
# Set the document root to RoR sample's public directory.
#
# Note: This is the last NameTrans directive.
#
NameTrans fn=document-root root="/ruby/samples/hello-world/public"
...
...
</Object>
...
...
#
# Object to handle the RoR application requests.
# Here, app-path must point to the dispatch.fcgi script of the RoR sample.
#
<Object name="rubyTest">
Service fn="responder-fastcgi" app-path="/ruby/samples/hello-world/public/dispatch.fcgi"
bind-path="localhost:4334" app-env="RAILS_ENV=production"
app-env="RUBYLIB=/usr/local/lib/ruby/1.8"
</Object>
|
% Web-Server-install-dir /bin/wadm pull-config --user=admin --config= CONFIG hostname http://localhost:80/hello/sayhello, where localhost and 80 are the host name and port number of Web Server 7.0, respectively. Hello! This is a simple example. Configuring Web Server 7.0 to run RoR with FastCGI is simple and hassle-free. A future article will describe how to run JRuby on Web Server 7.0. Stay tuned!
