Wednesday, November 30, 2011

Installing Ruby 1.9.3 using RVM on Mac OS Lion

ERROR: The provided CC(gcc) is LLVM based, it is not yet fully supported by ruby and gems, please read `rvm requirements`.

1) Download Xcode 4.2.x via App Store.
2) Go to Applications folder and click Install Xcode
3) Download and install GCC from https://github.com/kennethreitz/osx-gcc-installer
4) In a new terminal run : export CC=gcc
and then run : rvm install 1.9.3
5) You may also want to upgrade ruby gems by running:
gem update --system

Wednesday, November 02, 2011

ActiveRecord::Relation, undefined method error

If you are using the active record relationships to access columns, for instance:

Article has many comments
article.comments.where("spam = ?", false).order("created_at asc")

This returns ActiveRelation object that does not fire the query. Only when you loop through the results you can access the columns of comments objects. If you want to force the call to the database just append "all" to it like this:

article.comments.where("spam = ?", false).order("created_at asc").all