Using Ruby on Rails
Summary
Ruby on Rails is an open-source Web application development framework for developing database-backed web applications in Ruby according to the Model-View-Controller pattern.
Included on this page:
- Application Setup Instructions
- Rails Database Connection Configuration
- Ruby Gems on Your Account
- Resources
- Documentation
Application Setup Instructions
Create your Rails application directory
-
Log in to your Dante or home.myuw.net account with Tera Term or another terminal emulator.
Press the O key for Other, then press the W key to drop into the Web development environment (Vergil or Socrates). cd to public_html.
Run the rails command to create your Rails application directory.
rails appname-version
You need to give your rails application directory a different name than the name you want to use to access it. If you don't want to use a version number, then call it something else. Since you're going to access the application at a different directory name than the one you're using for the application directory, feel free to make this application directory name more descriptive.
Set up the Rails application directory to work with the Apache web server
Create a symbolic link to the public folder in your application directory.
ln -s appname-version/public appname
-
Edit the .htaccess file in the appname-version/public directory so that it can rewrite requests to the symbolically linked folder. You can do this by adding a RewriteBase directive to the .htaccess file just before the first RewriteRule directive. You will also need to comment out the Options directive on the fourth line of the .htaccess file as shown below.
# General Apache options AddHandler fastcgi-script .fcgi AddHandler cgi-script .cgi #Options +FollowSymLinks +ExecCGI # If you don't want Rails to look in certain directories, # use the following rewrite rules so that Apache won't rewrite certain requests # # Example: # RewriteCond %{REQUEST_URI} ^/notrails.* # RewriteRule .* - [L] # Redirect all requests not available on the filesystem to Rails # By default the cgi dispatcher is used which is very slow # # For better performance replace the dispatcher with the fastcgi one # # Example: # RewriteRule ^(.*)$ dispatch.fcgi [QSA,L] RewriteEngine On # If your Rails application is accessed via an Alias directive, # then you MUST also set the RewriteBase in this htaccess file. # # Example: # Alias /myrailsapp /path/to/myrailsapp/public # RewriteBase /myrailsapp RewriteBase /UWNetID/appname RewriteRule ^$ index.html [QSA] RewriteRule ^([^.]+)$ $1.html [QSA] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ dispatch.cgi [QSA,L] # In case Rails experiences terminal errors # Instead of displaying this message you can supply a file here which will be rendered instead # # Example: # ErrorDocument 500 /500.html ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
UWNetID should be substituted for your UWNetID and appname should be the name of your application (the same one you used to create the symbolic link).
Now you should try going to your application with a browser and see if it displays the "Welcome aboard" page that means your Rails application is working.
Your application should be at a URL like http://accountType.washington.edu/UWNetID/appname where accountType is staff, faculty, depts, courses or students, and UWNetID is your UW NetID.
Rails Database Connection Configuration
The database configuration for a Rails application is stored in
appdir/config/database.yml. There are separate configuration
sections for development, test, and production environments. The default is
development, so you can start by configuring that environment.
I'll assume that we're starting in the Rails application directory.
Open the database configuration file
config/database.yml.pico config/database.yml
Fill out the development section of the database configuration file. Remember to add a line specifying the port after the line "host:".
development: adapter: mysql database: (The name of the database you want the app to connect to) username: root (or whatever user you want to connect as) password: (The database password for the user specified on the line abo host: (ovid.u.washington.edu or vergil.u.washington.edu, depending on where you are running MySQL. Is the account staff/faculty/course/depts or student?) port: (You will have to add this line. It should be the port you're running MySQL on.)
Save the file and exit pico.
That should do it. Write to help@u.washington.edu if this doesn't work.
Ruby Gems on Your Account
It is possible to request that Ruby gems be installed system-wide, but this process usually takes a while. You can request software be installed using the Software Request Form. If you want to use a gem right away, you can install it on your own account using these instructions.
Change directories to your Web directory.
cd `wwwhome`
Create a directory to hold the gem(s) you want to install. Mine is called "gemrep".
mkdir gemrep
Install the
sourcesgem to thegemrepdirectory.gem install sources -i gemrep
Set the GEM_HOME environment variable to the path of the directory you just created for gems in your Web directory.
If you're using the bash shell, then you should can set the GEM_HOME environment variable by adding the following line to your
.profilefile.export GEM_HOME="/hw03/d20/UWNetID/gemrep"
Since I use the tcsh shell, I use a different method. This method also applies to the csh shell. Here's the line in my
.cshrcthat I use to set this environment variable:setenv GEM_HOME "/hw03/d20/UWNetID/gemrep"
Replace /hw03/d20/UWNetID with the path to your Web directory, which you can find using the wwwhome command.
Log out and back in, or set the environment variable for your current shell.
If you don't want to log out and back in to your account, you can set the environment variable by executing the same line that you just put in the
.profileor.cshrcfile.Install the gem(s) you want to use.
gem install gem_name
Make sure to use the name of the gem you want to install, rather than gem_name.
Some gems have dependencies, so you may have to install gems other than the one you're trying for in order to get it to install.
You can list the gems that are installed on your account using the following command:
gem list --local
The output of this command should include the gem(s) you just installed.
In order to get your Rails applications to use the gem repository that you just set up, you'll have to add a line to the public/dispatch.cgi file.
Add the following line to public/dispatch.cgi right after the first line:
ENV['GEM_PATH'] = "/hw03/d20/UWNetID/gemrep"
Make sure to replace the highlighted portion of the path with the path to your gem repository.
Now your Rails application should be using your new gem repository.
