Quick/Easy Startup Notes for Ruby on Rails
SSH to the
Development Server and run the commands below to create a brand new Rails project.
Create the rails project:
cd /var/www/
rails <projectname>
cd <projectname>
ruby -i -pe 'gsub!("#!/usr/local/bin/ruby", "#!/usr/bin/env ruby")' \
public/dispatch.* script/*
Create the postgres user and databases:
su postgres
createuser -P -d -A <projectname>
createdb -U <projectname> <projectname>_development
createdb -U <projectname> <projectname>_test
createdb -U <projectname> <projectname>_production
exit
Edit database config and create a table:
vi config/database.yml # change necessary settings (i.e. database adapter)
psql -U <projectname> <projectname>_development
> create table <name> (
id SERIAL NOT NULL UNIQUE,
name varchar(20),
PRIMARY KEY("id")
) # <name> should be plural (ex: categories)
> \q
Make controllers and models:
# all references to <name> below should be singular (ex: category)
script/generate controller <name>
script/generate model <name>
vi app/controllers/<name>_controller.rb # add the line "scaffold :<name>"
Regardless of whether or not you use virtual hosting (detailed below), you may need to add the following line somewhere in your Apache configuration (
/etc/apache2/sites-available/whatever
for example):
RewriteEngine On
With Virtual Hosting
Almost done! Now you have to make a virtual host in Apache. Go to
/etc/apache2/sites-available
and copy the
biorails
file to
<projectname>
. Edit the
<projectname>
file you just created and change all instances of
biorails
to
<projectname>
. Also, change the port numbers at the top to something other than
12345. Make a symbolic link from the file you just created to
/etc/apache2/sites-enabled/
. Next, edit
/etc/apache2/ports.conf
and add the port of your new virtual host, and then open up a port in iptables by running something like this:
iptables -A INPUT -p tcp -m tcp --dport <port> -j ACCEPT
Restart Apache, and then go to http://debian.mc.vanderbilt.edu:<port>/<name> and you have a simple web interface to your database! Easy.
Without Virtual Hosting
Create an alias and directory entry in the apache configuration (
/etc/apache2/sites-available/default
) to the Rails public directory. Example:
Alias /bioclinical/ /var/www/bioclinical/public/
<Directory /var/www/bioclinical>
Options ExecCGI FollowSymLinks
AllowOverride all
Order allow,deny
allow from all
</Directory>
Note: You must add a directive in the /var/www/<projectname>/public/.htaccess file, or mod_rewrite won't work correctly and Rails won't run. Add the following line somewhere in the file:
RewriteBase /<projectname>
Happy Railing!
Miscellaneous Configuration Notes
If you want to have a controller serve your application root directory (i.e.
http://debian.mc.vanderbilt.edu/bioclinical/) instead of using
public/index.html
, you need to edit the
config/routes.rb
file. Go
here for detailed instructions.
For fast cgi, look here:
http://wiki.rubyonrails.org/rails/pages/RailsOnDebianStable
And here:
http://wiki.rubyonrails.com/rails/pages/HowtoSetupApacheWithFastCGIAndRubyBindings