Another Example of why Bundler is so Great

I had the occasion to integrate a custom signup form into a Constant Contact account via their API today. Since my little app was using Ruby (via Sinatra) that means that someone had already done the hard work of writing a library to access Constant Contact for me.

The constant contact gem (https://github.com/idris/constant_contact.git) worked really well, but I had an initial problem trying to form a valid XML request to the API (lots of ActiveResource::BadRequest errors).

Turns out the issue was with my dependencies, specifically, the dependency on ActiveResource. The ConstantContact gem (at the time of writing, anyway) has an explicit dependency on ActiveResource, but specifies no version number. As such, the gem will use the latest version of ActiveResource on my system, 3.0.3. Since the API has changed in 3.0.3 from the 2.3.x series, the gem was not working correctly.

Luckily, Bundler exists just for this type of situation. One quick change later, and my project Gemfile looked like this:


source :rubygems
gem 'sinatra'
gem 'constant_contact', :git => 'git://github.com/idris/constant_contact.git'
gem 'activeresource', "~>2.3.10"


And boom, the gem was working.

I cannot overstate how much easier Bundler makes my life. I use it on every new project I manage, be it Rails 3, Rails 2.3.x, or Sinatra. It's really worth it.