Monday, December 24, 2007

multiple rails environments

For the Sunshine Organics website that I'm redoing, one of the design decisions I made was to have separate Rails servers for each city, the added complexity of keeping track of all the cities in one database just got too complicated.

So now I'm working on having multiple Rails projects being launched out of one directory, some of those websites will be normal websites, and some of them will correspond to sites where they don't have a warehouse to stock groceries, these will be called "sub" websites.

I've found a few resources to help me in launching multiple Rails projects from the same directory, basically it boils down to having different RAILS_ENV environment variables set for each one.

The links:

Deploying to Multiple Rails Environments - from "my hovercraft is full of eels"
Guide to environments in Rails
dry out your database - For this one, it's an interesting idea, but I find it way too convoluted. I just repeat the section, and find this much clearer:

What I did:

I made a new entry in database.yml for cv_development:

adapter: mysql
database: sunshine_cv_development
username: ****
password: ****
socket: /var/lib/mysql/mysql.sock

Then I copied over the existing development.rb file:

cp config/environments/development.rb config/environments/cv_development.rb

Then migrated:

export RAILS_ENV=cv_development && rake db:migrate

Made a new mongrel configuration file called "mongrel_cv_cluster.yml"

user: sness
cwd: /home/sness/nDEV/sunshine
port: "9632"
environment: cv_development
group: sness
pid_file: log/
servers: 1

Then started mongrel:

mongrel_rails cluster::restart -C /home/sness/nDEV/sunshine/config/mongrel_cv_cluster.yml