Ruby on Rails in Action
In this section I will explain a quick walkthrough on setting up RoR on On my first post I have mentioned that Ruby on Rails are separate packages combined to work as one, that is why there are two basic packages we need to install.
1. Installing Ruby
Download the Ruby one-click installer. After downloading install the package. Follow the instructions accordingly.
2. Update the Gem Package
Open a new session of command prompt (Start > Run > type in: cmd) and locate the ruby bin directory which by default “C:\ruby\bin”. After that we need to update the gem package by typing:
C:\rubyinstalldirectory\bin> gem update
The gem package will be updating, just wait. If you are prompted with a screen like this:
C:\ruby\bin>gem update Updating installed gems... Bulk updating Gem source index for: gems.rubyforge.org Attempting remote update of fxruby Select which gem to install for your platform (i386-mswin32) 1. fxruby 1.6.11 (ruby) 2. fxruby 1.6.11 (mswin32) 3. fxruby 1.6.10 (mswin32) 4. fxruby 1.6.10 (ruby) 5. Skip this gem 6. Cancel installation > 2 Successfully installed fxruby-1.6.11-mswin32 Installing ri documentation for fxruby-1.6.11-mswin32… … …
Select the appropriate action, I selected the number 2 option. This may take a while so be patient. Other options will also be displayed which requires you to choose, just choose the latest version for mswin32 platform.
After that, we need to install Rails and its dependencies, on command prompt type in:
gem install rails --include-dependencies
3. Configure Apache
At this point we already have installed Ruby on Rails, we can create application already but we still need to change the apache configuration to add ruby’s module in order to tie in RoR into Apache. Go to your apache’s httpd.conf and make sure to enable the following modules:
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule vhost_alias_module modules/mod_vhost_alias.so
After this we need to download RubyForApache, this will install the modules we need for apache. Next is run the setup program, it will basically look for the default installation folder for RubyForApache, Apache folder and Ruby on Rails directory just provide the right path and finish the installation.
Add the following codes on your httpd.conf
LoadModule fastcgi_module modules/mod_fastcgi.so
<fModule mod_fastcgi.c>
AddHandler fastcgi-script .fcgi
</IfModule>
LoadModule ruby_module modules/mod_ruby.so
<IfModule mod_ruby.c>
# for Apache::RubyRun
RubyRequire apache/ruby–run
# exec files under /ruby as Ruby scripts.
<Location /ruby>
SetHandler ruby–object
RubyHandler Apache::RubyRun.instance
Options +ExecCGI
</Location>
# exec *.rbx as Ruby scripts.
<Files *.rbx>
SetHandler ruby–object
RubyHandler Apache::RubyRun.instance
</Files>
</IfModule>
Next restart the apache service. If Apache won’t restart just reboot your machine and it should be fine. If Apache still won’t restart you are probably getting entries in your Event Log for “Applications� similar to the following:
Cannot load C:/Apache2/modules/mod_ruby.so into server: The specified module could not be found Synt\ax error on line 176 of C:/Apache2/conf/httpd.conf:
To resolve this make sure the path to your Ruby install “binâ€? directory is in your system path. In the example I have provided so far you need to append “;c:\ruby\binâ€? to the end of your current path. I am using windows XP Pro. In order to modify my path I had to right click on “My Computerâ€? choose “Propertiesâ€? and from the dropdown menu. A dialog window should appear. I then clicked on the advanced tab; the environmental variables button, and in the system variables section I scrolled down until I found “pathâ€?, click edit, add the ruby’s path above to the end, click OK. click OK again, then restart for the change to take affect.
4. Creating a Ruby on Rails Application
To create a new application directory open your command prompt and use the following command:
rubybindirectory = your ruby bin directory for this example C:\ruby\bin
apache_htdocs = apache webserver path for this example C:\Apache2
appname = your RoR application name for this example myApp
C:rubybindirectory> rails C:/apache_htdocs/htdocs/appname
5. Configuring a Ruby on Rails Application
After creating your application, we need to tweak some settings on your application folder, go to your application path’s public folder, in this example it is C:\Apache2\htdocs\myApp\public\
at this point you need to focus on two files namely .htaccess and dispatch.fcgi
on .htaccess, look for the following code:
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
change it to:
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
comment the apache section on your .htaccess as follows:
# General Apache options # AddHandler fastcgi-script .fcgi # AddHandler cgi-script .cgi # Options +FollowSymLinks +ExecCGI
on dispatch.fcgi, make sure the first line which reference the path of your ruby on rails installation folder is correct:
#!c:/ruby/bin/ruby
And finally, go back to your httpd.conf file and add a virtual host entry as follows:
#################################
# RUBY SETUP
#################################
<VirtualHost *:80>
ServerName rails
DocumentRoot "c:/path/to/your/rails/app/public"
<Directory "c:/path/to/your/rails/app/public/">
Options ExecCGI FollowSymLinks
AllowOverride all
Allow from all
Order allow,deny
AddHandler cgi-script .cgi
AddHandler fastcgi-script .fcgi
</Directory>
</VirtualHost>
#################################
# RUBY SETUP
#################################
make sure to change the path to your application path. Restart your apache server again. Browse your application on the browser and Have Fun!!!
Bookmark This!








I am Filipino Web Developer, focusing on PHP in LAMP framework. As a kid, I spent a lot of my time exploring computers and computer games from Atari to PS, from INTEL 80286 - CoreDuo. I am happily married, with two kids. Currently working in Japan as an IT Engineer.