Computing & Communications Center
Helpdesk

Ruby on Rails at WPI

Ruby on Rails code based on Agile Web Development with Rails 1st edition has to be adjusted in order to run at WPI. We'll cover the changes that we've come across below. We noted if these changes are a deviation from the book's code or if they are an extra step needed to ensure the application runs.

Creating the framework (deviation)

The book uses the code 'rails depot'. Change it to 'rails depot --database=mysql' to point it to the correct database type.
The book assumes SQLlite is being used as the database. WPI uses MySQL.

Specify the MySQL plug-in (extra step)

Rails has released new versions since this edition of the book. The new Rails version is more modular, so some old built-ins need to be specified as plug-ins.

  1. Edit the file ../depot/config/environment.rb
  2. Add the line: config.gem "mysql"

Specify the application's base URL on the web server (extra step)

This line limits the application to controlling URLS under the URL set above.

  1. Edit the file ../depot/config/environment.rb
  2. Add the line: config.action_controller.relative_url_root = '/~username/depot
    Replace username with your WPI username.

Create the maintenance application (deviation)

The syntax for this command is outdated in the 1st edition.

Use 'ruby script/generate scaffold product title:string description:text image_url:string price:float' instead of 'ruby script/generate scaffold Product Admin'.

Create CGI "dispatchers" (extra step)

Rails assumes it will run on Ruby-specific server software. WPI runs a general-purpose web server. This creates a bridge between our web server and Rails. The command, rake, is a standard part of Rails.

Add the following line: 'rake rails:update:generate_dispatchers'

Create ".htaccess" files to call dispatcher (extra step)

This tells the web server to use the dispatcher created above to serve any request for a URL within the "RewriteBase" directory.

Add the following to the file "../depot/.htaccess"
#------------------------------------
RewriteEngine On
RewriteBase /~username/depot
AddHandler fastcgi-script .fcgi

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^<.*>$ public/dispatch.fcgi
#------------------------------------

Starting the application (skipped step)

WPI's user web server is already running, erego, no need to start it. Just browse to the application URL and it will automatically start after a few seconds. Skip the following code in the 1st Edition book: 'ruby script/server'

Maintained by itweb.
Last modified: Feb 26, 2010, 20:31 UTC
[WPI] [Home] [Back]