my recent reads..

Multi-tenancy with Rails

RedDotRubyConf 2011 in Singapore is over. It was an amazing event (ryan takes notes so we don't have to - day#1 day#2)

Somehow I managed to cheat my way into a line-up of legendary speakers that included Matz himself. Here are the slides..


I spoke about multi-tenancy - what it is and why it's increasingly relevant for Rails development. It dives a little into four of the many approaches and ends with the challenge: Isn't it about time there was a 'Rails Way'?

Blogarhythm: So Many Ways POP DISASTER


read more and comment..

jQuery UI AddToCalendar update

Thanks to nfarina for a patch to improve compatibility with older IE versions.. jQuery UI AddToCal widget is stepped to 0.1.1 and now listed in the jQuery plugin store.

To recap .. use AddToCal if you want to offer your website visitors the ability to add any events you list or present on your site to their own calendar. It supports Google Calendar, Microsoft Live Calendar, Yahoo! Calendar, 30boxes, any iCal or vCalendar compatible desktop application (and you can extend it to support any special calendar software you might be dealing with).

See my previous post that describes how to use it in a bit more detail..

Blogarhythm: Birthday
read more and comment..

Paranoid Yak Shaving

So a few weeks ago I found myself wanting "soft-delete" in a Rails app. Ruby Toolbox is a little long in the tooth on the subject, but after a little more research I discovered xpond's paranoid project that was just what I wanted:

  • packaged as a gem, not a plugin

  • built for Rails 3 (arel-aware in particular)

  • can be selectively applied to your models

All was cool, except at about the same time we updated to Rails 3.0.3 and it broke (as it turned out, due to changes in AREL 2.0.6 internals).

One of the beautiful things about github and the way it's been adopted by the ruby/rails community in particular is that it makes it so damn easy to just dive in and help update code originally contributed by other people. So paranoid needs updating for Rails 3.0.3? No problem - fork it, diagnose the issue and push your fixes back up to github.

But that's also a great recipe for yak shaving ;-)

The fixes are yet to make it into the released gem, but if you desparately need 3.0.3 support you can install from my repo. i.e. in your Gemfile:

gem 'paranoid', '~> 0.0.10', :require => 'paranoid', :git => 'git://github.com/tardate/paranoid'


Blogarhythm: Paranoid (of course - but this is the bluegrass version!)
read more and comment..

CruiseControlling Ruby 1.9.2 and Rails 3.0.2

CruiseControl for Ruby from ThoughWorks has long been one of the easiest ways to your rails project under continuous integration.

But there's still an issue that it can't run under Ruby 1.9.x. That's not very good if you are targeting 1.9.2 for your project.

Here's a quick recipe for how you can build a 1.9.2 project with CC, using the wonders of rvm..

# download and unpack CC to /usr/local/cruisecontrol-1.4.0 (or where you like)
# for convenience, add .rvmrc in /usr/local/cruisecontrol-1.4.0 to have it run 1.8.7
echo "rvm 1.8.7-p302" > /usr/local/cruisecontrol-1.4.0/.rvmrc
# configure CC:
cd /usr/local/cruisecontrol-1.4.0
./cruise add my_project_name --source-control git --repository git@github.com:myname/myproject.git
# ^^ This will initialize the ~/.cruise/projects/my_project_name folder for a git-based project

# if you have an .rvmrc file in your git repo, pre-emptively trust it to avoid clogging CC:
mkdir ~/.cruise/projects/my_project_name
rvm rvmrc trust ~/.cruise/projects/my_project_name

In ~/.cruise/projects/my_project_name, edit cruise_config.rb to run a shell script instead of the standard build task (I'm calling it ccbuild.sh and it will be in the root of my git repo):
Project.configure do |project|
# [.. other stuff ..]
project.build_command = './ccbuild.sh'
# [.. other stuff ..]
end

Add ccbuild.sh to your repository (don't forget to chmod u+x it). It needs to ensure rvm script is loaded and activate the correct ruby & gemset.

The script initialization is necessary because it seems the way CC spawns the shell script it doesn't pick up the rvm initialization you might already have in .bash_profile. Without rvm script initialization, "rvm" will invoke the binary which can't make the direct environment mods it needs to do.

Here's what I have in ccbuild.sh:
#!/bin/bash

if [ "$(type rvm | head -1)" != "rvm is a function" ]
then
source ~/.rvm/scripts/rvm || exit 1
fi

if [ "$(type rvm | head -1)" != "rvm is a function" ]
then
echo "rvm not properly installed and available"
exit 1
fi

rvm use 1.9.2-p0@mygemsetname --create
bundle check || bundle install || exit 1
rake # setup to run all required tests by default

Once that's checked in and pushed to the repo, you can kick-off CC:

cd /usr/local/cruisecontrol-1.4.0
./cruise start

Now my ccmenu is green, and CruiseControl is running my project under 1.9.2 and rails 3.0.2;-)

Blogarhythm: Waiting for the light ART-SCHOOL
read more and comment..