Skip to content

PostgreSQL, Ruby, and Rails: WIN

This is a follow-up to my post: PostgreSQL, Ruby, and Rails: I Quit.

So I finally have a working machine with the following installed and ready to rock:

  • Ruby and Rails: From MacPorts

    • Tip: Don’t forget: “source ~/.profile”
    • Do not touch /etc/profile, even though Robby said so. (Although, I’d like to ask why he said to modify /etc/profile…) Everything else in that walkthrough is awesome.
      • /etc/profile is read-only. I really didn’t want to change this, and I even went and looked into /etc/paths.d. Don’t. You don’t need to.
    • Why not use the native Ruby that was shipped with Apple? That’s for another time.
  • Passenger(mod_rails) and PassengerPanes

    • My problem was after installing Ruby and Rubygems through MacPorts, I didn’t update the $PATH.
      • You do not need to create symbolic links (“ln”) at all. Just make sure to “source ~/.profile” after you’re done messing with the PATH variable in it.
    • PassengerPanes is amazing. Use it, and love it if you’re doing any testing on your mac before capistrano’ing the whole thing on a test server.
  • Git

    • Simple installation as “git-core” on MacPorts. I didn’t have any problems with this one.
  • PostgreSQL

    • MacPorts again. Makes sure to also install pgAdmin3, a nice GUI for PostgreSQL.

Which Gem? How To Install It?

If you go to the RubyForge page, you’ll see two gems. I still don’t understand why the releases were named with the “rb-” prefix (maybe to distinguish that it’s a ruby gem). Regardless, there are two gems listed “pg” and “postgres”.

Although “postgres” seems to be more out of date, this is the one that you’re going to want for the near future. Eventually, you’ll be wanting the “pg” gem. If you read some of the news, you’ll see that they’re also working on making sure that it works with Ruby 1.9.

Following yet another great walkthrough, you’re going to want to install it in this manner on an Intel Mac (if you installed PostgreSQL through MacPorts).

sudo env ARCHFLAGS="-arch i386" \
  gem install postgres -- \
  --with-pgsql-lib=/opt/local/lib/postgresql83 \
  --with-pgsql-include=/opt/local/include/postgresql83

PostgreSQL with Rails

Now that PostgreSQL is talking with Ruby, now let’s make Rails talk with it.

In config/database.yml, make sure the adaptor is set to “postgresql”, like so.

development:
adapter: postgresql
encoding: unicode
database: projectname_development
pool: 5
username: username
password: password

That was taken from the generated database.yml, which is done this way when you start your rails project.

rails projectname -d postgresql

My Thanks and Apologies

Thank you to all the blogs I’ve visited over and over again through Google queries. Some information was outdated (and at one point, this will also be outdated), but that’s how it is with anything web development, especially anything to do with Rails it seems. The speed at which this community keeps innovating continues to surprise me, and makes me happy that I made that choice to go with Rails (even though I struggled through it from time to time).

This doesn’t mean I’m done. Oh no, now I have to actually design, test, and develop on the stack I’ve created. I’m sure I’ll be sitting in on the Rails IRC room a couple times.

My apologies for not having a more complete walkthrough, although, I hope the links I’ve included will help out more. If you have any questions, just leave a comment, and I’ll try to help.

Now to keep on hackin’.

Categories: HanMeta, Web Development.

Tags: , , ,

Comment Feed

5 Responses

  1. On Mac OS X 10.5.6, I installed the "canned" .dmg from PostgreSQL (8.3.7). This installs to /Library/PostgreSQL/8.3, quite unlike macports. Anyway, the following worked for me to get the latest ruby-pg gem:

    sudo env ARCHFLAGS="-arch i386" gem install ruby-pg — –with-pgsql-dir=/Library/PostgreSQL/8.3

  2. I tried using ruby-pg postgres adapter forgetting my postgres working onto my windows machine but the gem installtion ended up giving some native gem building extension error. But postgres-pr gave me a lightining fast solution to my issue..Thanks for the nice post !!!!

  3. THANKS!!!! This, and the comment from the previous post about using the right rake, and I’m up and running on OS X 10.6, rails 2.3.4, postgres (gem) 0.7.9, and Postgresql 8.4.

    And ditto for making sure you have the right path to your PSQL distro. In my case it meant changing it to /opt/local/lib/postgresql84

    Chris BloomOctober 9, 2009 @ 8:21 PMReply
  4. Sorry if I’ve managed to flood your pending-approval queue with the same comment over and over again, but something is broken with your comment form – it keeps redirecting me to http://joshkim.org/comment-page-/#comment- and a Page Not Found message.

  5. Thanks for the comment. The comments are seriously broken, and I’m looking into it tonight.



Some HTML is OK

or, reply to this post via trackback.

By submitting a comment here you grant this site a perpetual license to reproduce your words and name/web site in attribution.