Ruby on Rails Guide

This is a guide to running ruby on rails applications on the TJ webserver. This is not a general guide to creating and running ruby on rails applications. The ruby on rails website has plenty of information on getting started with ruby on rails.

Logging into www.tjhsst.edu
Log into www.tjhsst.edu just as you would any other host with ssh. If accessing www from a workstation or remote, you should automatically be authenticated. If accessing www from another host, or if you are not automatically authenticated, use the same username and password that you would use to access a workstation.

Suggested Configuration for our Webserver
As of July, 2008, our webserver is running version 2.1.0 of ruby on rails and ruby 1.8.5. Please ensure your application works with this configuration.

When deploying your rails application, it is desirable to not have your entire application, including configuration files, to be available to everyone. For this reason, when building a rails application, we suggest that you protect access to your files with an .htaccess file, or actually store your application in a directory that is not in your web-docs directory.

Protecting your Application with an .htaccess File
For this example, let's assume that I have my rails application, rails, which I want to appear at http://www.tjhsst.edu/~user/rails/. Instead of putting my application in a directory named, I am going to put it in a directory named.

Next, in order for my application to appear at, create a symbolic link to the. ln -s rails-app/public/ rails Next, create an .htaccess file similar to the following in your rails-app directory: Order allow,deny Deny from * Now our application directory is safe, so the code and configuration details (including the database username and password) cannot be viewed in a web browser.
 * 1) In my web-docs directory

Making your Website Accessible through the Webserver
Another  file is necessary in order to correctly redirect webserver requests into your rails application. Place the following  file example in your applications'   directory. If you are trying to configure an existing application that already has an  file, do not replace the existing file, but merge the differences between the two files in order to not overwrite any custom modifications for your particular application.

Example  file: RewriteBase (URL of your application)
 * 1) Example:
 * 2)    RewriteBase /~user/myrailsapp

AddHandler fcgid-script .fcgi
 * 1) Make sure the server knows about .fcgi scripts

Options +FollowSymLinks +ExecCGI
 * 1) Follow symbolic links and execute CGI fils


 * 1) If you don't want Rails to look in certain directories,
 * 2) use the following rewrite rules so that Apache won't rewrite certain requests
 * 3) Example:
 * 4)   RewriteCond %{REQUEST_URI} ^/notrails.*
 * 5)   RewriteRule .* - [L]
 * 1)   RewriteRule .* - [L]

RewriteEngine On RewriteRule ^$ index.html [QSA] RewriteRule ^([^.]+)$ $1.html [QSA] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
 * 1) Redirect all requests not available on the filesystem to Rails
 * 2) By default the cgi dispatcher is used which is very slow
 * 1) Please refer to the "Server Process Instances" section at the bottom of the
 * 2) ruby on rails guide in Livedoc (http://www.tjhsst.edu/admin/livedoc/)
 * 3) before uncommenting the following line.
 * 4) RewriteRule ^(.*)$ dispatch.cgi [QSA,L]


 * 1) In order to run rails in a mode other than production
 * 2) Example:
 * 3)   SetEnv RAILS_ENV development
 * 1)   SetEnv RAILS_ENV development


 * 1) In case Rails experiences terminal errors, specify the error to display
 * 2) Example:
 * 3)   ErrorDocument 500 /500.html
 * 4)   ErrorDocument 500 " Application error Rails application failed to start properly"
 * 5) If this is not specified, the generic error page will be displayed
 * 1) If this is not specified, the generic error page will be displayed
 * 1) If this is not specified, the generic error page will be displayed

File Permissions
Ruby on rails needs write permissions to certain directories in the application. Execute the following command from within your application's main directory in order to enable write access. find log tmp -type d -exec fs sa {} www-data write \; If you find that other directories need to have writable from the webserver, add the names of the directories to the list between  and.
 * 1) From your application's main directory

Gem Installation
If you need any ruby gems installed on our server, contact a sysadmin. In most cases, we are happy to install the gems needed by your application. Alternatively, you can install the gems locally for your installation.

Server Process Instances
In order to accelerate the performance of ruby on rails applications, we use something called fcgid (a binary-compatible FastCGI implementation) to keep ruby instances running in the background for a certain timeperiod. As a result, if you make certain modifications to your rails configuration, such as changing the database username and password, these changes may not take effect immediately. The server process will not shutdown as long as there is traffic viewing your page, so allow your page to time out, or make the noted change in the second  file above. If you make the modification in the  file, please reverse the change as soon as possible. While the change is in place, your site will take longer to service requests, and our server will experience an additional load for each request. The sysadmins can reset the server process, so please contact a sysadmin as soon as possible in order to speed-up the server for everyone.