Too Cool for Internet Explorer

Friday, June 03, 2005


Hack-a-lot: Ruby on Rails, Tiger and PostgreSQL

Although I had to do lot of work to do for my written tests in the last few days, I had to play around with Ruby on Rails. Yeah, had to.
Maybe you remember me installing Oracle 10g on Mac OSX? - Now I wanted to use it with RoR, of course. But it seemed that either Oracle 10g did not want to speak to the Oracle8 adapter or RoR has no idea what a tablespace and what a database is. I tried everything, but with no luck at all.

Now I installed PostgreSQL on my iBook, too. No problem, it's not as large as Oracle and it will help me finding out, if I am dumb or just despairing on some software version conflicts.

Installing PostgreSQL on Tiger is the same procedure as on Panther, Jaguar, Kitten, whatever: you just have to install readline (via fink or elsewise) and then compile PostgreSQL, create a default user who owns the database, create a database and start the server.

Everything will work with no trouble until you want to hit the database with ruby. Once again the driver/adapter will be a pain in the a**, because gem install postgres-pr just will install without any errors but not work at all. Somewhere you get the hint to just use the other libs and do a gem install postgres.

That one will not install offhand. One and a half hour later you then have the solution:

gem install postgres

cd /usr/lib/ruby/gems/1.8/gems/postgres-0.7.1/

ruby extconf.rb --with-pgsql-include-dir=/usr/local/pgsql/include
--with-pgsql-lib-dir=/usr/local/pgsql/lib

make install

Now the adapter is installed and you may start editing your config/database.yml file.

And: Yesterday I saw that Flo put some links together for Ruby on Rails beginners. I haven't had a closer look at it, but I will do that later tonight.

Technorati Tags: , , , ,

Bookmark this on Del.icio.us
posted by madhatter @ 8:53 PM


9 Comments:

At 2:13 AM, Anonymous Anonymous said...

Another command that will work is

gem install postgres -- --with-pgsql-include-dir=/usr/local/pgsql/include --with-pgsql-lib-dir=/usr/local/pgsql/lib

The -- allows the --with options to be passed directly to the internal invocation of ruby extconf.rb install postgres.

 
At 11:51 PM, Blogger madhatter said...

Yeah, I had some trouble figuring out the differences between accessing PostgreSQL and MySQL, too.
I installed Postgres from the sources (8.0.3) and readline from fink (http://fink.sf.net/).
I can't remember any other bigger problems.

 
At 5:53 AM, Anonymous Anonymous said...

FYI, I started a thread on this back when Tiger was in testing:

http://rubyforge.org/pipermail/ruby-dbi-devel/2005-March/000324.html

Funny thing is, if you compile ruby yourself and then install postgres-pr into that, everything works. I submitted the bug to Apple, but as of yet haven't heard anything. It's obviously something they've done with their install of Ruby.

 
At 1:20 PM, Anonymous Anonymous said...

For the postgresql8 package installed from darwinports, the follwing commandline worked to install the postgres gem:


sudo gem install postgres -- \
--with-pgsql-lib-dir=/usr/local/lib/pgsql8 \
--with-pgsql-include-dir=/usr/local/include/pgsql8

 
At 4:40 AM, Anonymous Anonymous said...

Stig Sandbeck Mathisen's suggestion will also work if you installed the PostgreSQL v8.0.1 package from entropy.ch

 
At 6:22 AM, Anonymous Anonymous said...

If you use the PostgreSQL8.dmg from http://pgsqlformac.sourceforge.net/ then you'll need to use this version:
gem install postgres -- --with-pgsql-include-dir=/Library/PostgreSQL8/include --with-pgsql-lib-dir=/Library/PostgreSQL8/lib

 
At 8:41 PM, Anonymous Anonymous said...

gem install postgres -- --with-pgsql-dir=/usr/local/pgsql

worked for me!

ps. the adapter name in database.yml is postgresql, not postgres

 
At 9:24 PM, Blogger madhatter said...

Thanks for the comments.

John, it sounds like I wrote the adapter's name is 'postgres'. But I didn't, did I?

 
At 12:09 AM, Anonymous Anonymous said...

We had a problem to compile on MacBook Core 2 Duo (64 bit) with Mac OS X 10.4.8:

postgres.c:222: warning: pointer targets in passing argument 1 of 'PQescapeBytea' differ in signedness

We changed line 222 to:

to = (char *)PQescapeBytea((unsigned char *)from,
from_len, &to_len);

and were successful with: make; make install;

 

Post a Comment

<< Home