Wednesday, July 14, 2010

Finding an Object's method using grep

I've found that would be pretty handy finding a method on an object :

1 - Use the Rails console
./server/console

2 - How to find a method by name :

Syntax.:
Object.new.methods.grep(/pattern/).sort

Example.:

User.new.methods.grep(/*[Uu]ser*/).sort

You also can compare two objects :

User.new.methods.grep(/*user*/).sort - Object.new.methods

Tuesday, December 22, 2009

Installing Postgres gems manually

Here is a way that I've found to install Postgres gems on Leopard Mac OS X :

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

It will launch a lot of errors, no worries, let's work that around :

First, set the enviroment variable :

# export ARCHFLAGS="-arch i386"

Go to the directory :
# YOUR_RAILS_INSTALL_DIR/.gem/ruby/1.8/gems/ruby-pg-0.7.9.2008.01.28/ext

Execute the following :
# ruby extconf.rb --with-pgsql-include=/usr/local/pgsql/include --with-pgsql-lib=/usr/local/pgsql/lib

(Change the PostGres installation directory accordingly )

From the sam directory execute :
gem install ruby-pg -- --with-pgsql-include-dir=/usr/local/pgsql/include/ --with-pgsql-lib-dir=/usr/local/pgsql/lib/

( This will install the postgres gems manually )

You should be good at this point.

Hope that helps.