Monday, November 19, 2007

NetBeans, Ruby on Rails, and PostgreSQL on Solaris

I needed to track down an issue with PostgreSQL and the Ruby on Rails support in NetBeans today, and in the process learned what you need to do to get PostgreSQL working on Solaris with NetBeans.

There are two approaches you can do. You can use the Cool Stack Ruby on Rails package, which is optimized for Solaris. Or you can use the JRuby/Ruby On Rails support that comes with NetBeans.

These instructions are for NetBeans 6 RC1, and assume you have installed the bundle with Ruby support or installed the plugin from the update center (see Tools->Plugins).

In either case, you need to install the Postgres driver gem for Ruby. This is easily done, just go to Tools->Ruby Gems, select the New Gems tab, search for "postgres" and pick "postgres-pr". This is the Ruby implementation. I had trouble installing the native implementation, I think I'm missing the postgres header files it needs.

postgres-gem.jpg

If you want to use JRuby and the Rails that comes with NetBeans, you're ready to go. When you create a new Ruby on Rails project, pick "postgres" as the database.

ruby-new-project.jpg

Now, there appears to be a problem with postgres-pr and JRuby, when it tries to use the Postgres UNIX file socket to connect to PostgreSQL. So edit your database.yml file and uncomment the following lines:

host: localhost
port: 5432

With that, you should be good to go.

If you want to use the Cool Stack implementation, first download and install the Ruby package. Then you need to point NetBeans to the CoolStack Rails implementation. Go to Tools->Options, and pick the tab for Ruby. Point Ruby Interpreter to the location for the interpreter, which by default should be /opt/coolstack/bin/ruby.

ruby-coolstack.jpg

When using Cool Stack Rails, you can use the UNIX socket, so you don't need to modify your database.yml file.

For more information on Postgres and Ruby, see the Ruby Wiki page.

No comments: