Archive for December 2009

L33t Links #59

Protected: Stop Whining About Rails 3

This post is password protected. To view it please enter your password below:


L33t Links #58

Back from Italy. Luckily I still have a week of till I have to get back to the real world. :)

This Blog is Going on a Vacation

Hello, readers of Caffeine Driven Development!

I’m heading off to Italy tomorrow morning to go skiing. I will be back either very late Saturday the 26th or very, very early in the morning the 27th. So during that period you’re actually going to check your RSS reader yourself. Awwwww. ;-)

See you when I get back!

Kind regards,
David Trasbo

L33t Links #57

PostgreSQL & Rails on Ubuntu

I work as a Ruby on Rails contractor for Enlight Solutions, and recently I got involved in a new project for which we wanted to use PostgreSQL because we were going to use Heroku for staging the application. Since I never used PostgreSQL on a project before, I just wanted to share with you how I got it up and running on my Ubuntu 9.10 machine.

The first thing you need to do in order to get it working is to install the postgresql package:

sudo apt-get install postgresql

Now install the postgresql-client package so that you can interact with PostgreSQL in the terminal:

sudo apt-get install postgresql-client

Then you need to install the pg gem to get the Ruby bindings for PostgreSQL:

sudo gem install pg

Next, run the following command to enter the PostgreSQL console as superuser:

sudo -u postgres psql

postgres is the user of PostgreSQL on your machine. In the console, run this command:

CREATE USER #{your_unix_username}

Replace #{your_unix_username} with the username you use to log in to your machine, in my case it’s just “david”. We’re not specifying a password because it’s our development environment – in production you should of course strive to keep things secure. Now let’s test if it’s working. First generate a Rails project which uses PostgreSQL:

rails pg_test -d postgresql

That should work just fine no matter what. Even if you haven’t installed PostgreSQL on your machine. However, if you haven’t installed PostgreSQL properly this will not work:

rake db:create

Run it and see what happens. It should work if you have followed the instructions above. Please note that you do not have to edit config/database.yml with your username. By default Rails will put the name of the application there, because that’s how you would usually set it up in production environment: create a separate user for each application. In this case, however, it works even if you leave username and password blank because we named our PostgreSQL user after our UNIX user. To illustrate the process of authentication inside PostgreSQL:

  • Does “username” match a user on the machine?
    • Yes
      • Is that user logged in?
        • Yes
          • OK!
        • No
          • Fail!
    • No
      • Normal authentication procedure

Please leave feedback if there’s something you think should be corrected or if you have difficulties getting it to work. Hope you found it useful!

L33t Links #56

L33t Links #55

L33t Links #54

L33t Links #53