February 7, 2005

Ruby on Rails on Mac

I've been getting the Ruby on Rails framework installed on my Powerbook in order to play with it and find out what everyone's so excited about, and because David is proposing it for a small upcoming project.

There's an excellent guide to installing Ruby on Rails on OS X, which gave me a clue about requirements and so on. I didn't follow it to the letter because (a) I am using fink, not darwinports and (b) I'm going to try and avoid running MySQL, opting for Postgres instead.

I installed Ruby 1.8.1 via fink. I grabbed the RubyGems package management framework (yet another package management framework ... sigh) from the RubyGems wiki. Finally, I did sudo gem install rails which is where I hit the first problem:

Successfully installed rails, version 0.9.5
Installing RDoc documentation for rails-0.9.5...
WARNING: Generating RDoc on .gem that may not have RDoc.

lib/rails_generator.rb:34:46: Skipping require of dynamic string: "#{path}/#{name}_generator.rb"
Installing RDoc documentation for rake-0.4.15...
Installing RDoc documentation for activerecord-1.6.0...
Installing RDoc documentation for actionpack-1.4.0...

lib/action_controller/scaffolding.rb:87:37: Skipping require of dynamic string: "#{model_id.id2name}"
ERROR: While executing gem ... (NoMethodError)
undefined method `find_module_named' for nil:NilClass

It looks like this is only a problem with documentation, so fingers crossed.

One thing I did note during the gem install process was that I was asked if I wanted to install each dependency individually - rather than the Debian-style "the following packages will also be installed" approach. I prefer Debian's method: it means I can just leave the install running, rather than having to keep a close eye on it. Perhaps a better example is perl's CPAN package installer ... but I can't remember how it behaves with dependencies. I seem to recall it follows them automatically, but it's been a while.

The other problem I have is installing Postgres. There are at least four options:

I opted for the Liyanage package - it's recent, and it's quick and easy to get running. A quick install of that, the startup item from the same page, and /usr/local/bin/createuser myusername, and I'm up and running.

To give me a quick overview of Rails, I decided to work through the excellent "Rolling with Ruby on Rails" tutorial at ONLamp.

The Rails Tutorial gave me the information for connecting to a Postgres database in Rails, and it was trivial to convert the ONLamp gratuitously-GUI MySQL setup to Postgres:

psql template1
create database cookbook;
\c cookbook
create table recipes (
id serial unique,
title text,
description text,
date date,
instructions text,
category_id integer
);
create table categories (
id serial unique,
name text
);

This is where I came temporarily unstuck: sudo gem install postgres. I got:

Attempting local installation of 'postgres'
Local gem file not found: postgres*.gem
Attempting remote installation of 'postgres'
Building native extensions. This could take a while...
ERROR: While executing gem ... (RuntimeError)
ERROR: Failed to build gem native extension.
Gem files will remain installed in /sw/lib/ruby/gems/1.8/gems/postgres-0.7.1 for inspection.
ruby extconf.rb install postgres\nchecking for cygwin32_socket() in -lwsock32... no
checking for socket() in -lsocket... no
checking for gethostbyname() in -linet... no
checking for gethostbyname() in -lnsl... no
checking for sys/un.h... yes
checking for socket()... no
checking for cygwin32_socket()... no

Results logged to /sw/lib/ruby/gems/1.8/gems/postgres-0.7.1/gem_make.out

Thankfully, sudo gem install postgres-pr worked. I don't really know what the difference is.

So now I have Ruby on Rails working. I'm going to play with it a bit more before passing judgement on it.

Posted by savs at February 7, 2005 1:38 AM