Ruby on Rails Ubuntu 8.10: Creating a Rails Application

Warning: count(): Parameter must be an array or an object that implements Countable in /nfs/c01/h05/mnt/6385/domains/ on line 65

After deploying Ubuntu 8.10 server, installing Ruby on Rails and all its prerequisites, and installing Phusion Passenger, there are just a few Passenger specific steps necessary to get your Rails application up and running.

Create a directory to house all of your Rails applications (you can put this wherever you like):

mkdir railsapps
cd railsapps

Create your Rails application (“first”) with a mysql database:

rails -d mysql first

Create a SymLink for Passenger to follow from your application/public directory to the Apache DocumentRoot/SubUri:

sudo ln -s ~/railsapps/first/public /var/www/first

Update the Apache config to let Passenger know about the application:

sudo vi /etc/apache2/sites-enabled/000-default

Append the following at the end of the config:

RailsBaseURI /first

Restart Apache to apply your changes:

sudo /etc/init.d/apache2 restart

Now that we have Apache and Passenger looking in the right places, we can get back to editing some of the Rails settings.

Change into our rails application root directory:

cd ~/railsapps/first

Edit the /railsapps/first/config/environment.rb file to notify rails that you are operating out of a SubURI

vi config/environment.rb

Just inside the end of the function “ do |config|” add the following:

config.action_controller.relative_url_root = "/first"

So the last few lines of your environment.rb file should look like:

  # Activate observers that should always be running
  # Please note that observers generated using script/generate observer need to have an _observer suffix
  # config.active_record.observers = :cacher, :garbage_collector, :forum_observer

  config.action_controller.relative_url_root = "/first"

Edit the /railsapps/first/config/database.yml file to make sure you have correctly specified your database login information

vi config/database.yml

Call rake to create your application database

rake db:create

Your first rails app is now up and running! You should be able to browse to it at http://YourServerURI/first