Blog An exploration of the art and
craft of software development

Heroku, Gemsets and Running Older Rails Apps

Posted by Marty Haught on Monday, December 13, 2010

For one of my clients, I was asked to take over an older app that is hosted on Heroku. Because this app still runs on 2.3.5 it needs an older version of Rack than the Heroku gem. If I wanted to have both the app and the heroku gem play nice along with thin and others, I either need to upgrade Rails or put Heroku somewhere else. Luckily, rvm gemsets gave me what seems to be the best solution in an unfortunate situation.

It’s now my standard practice when getting an older project (especially a rescue) to create a gemset and alias for that app. Here’s a quick snippet of the commands I run:


rvm use ruby-1.8.7-p302 # or whatever ruby version your app uses such as 
rvm gemset create clientapp
rvm alias create clientapp ruby-1.8.7-p302@clientapp

# install all your gems
gem install rails --version 2.3.5 
rake gems:install
...

# make your .rvmrc file 
echo "rvm ruby-1.8.7-p302@clientapp" > .rvmrc

In order to run the heroku commands, you’ll need to install the heroku gem. Unfortunately for our project, the heroku gem needed a newer version of rack and one that doesn’t play nice with Rails 2.3.5, which seems to remain a very popular version of Rails. Two of my latest projects still run on this. To get around this I created a Heroku gemset. My default Ruby is 1.9.2 so I first switch to that:


rvm use ruby-1.9.2-p0
rvm gemset create heroku
gem install heroku
rvm alias create heroku ruby-1.9.2-p0@heroku

This isn’t ideal and if you’re only using newer versions of Rails and the current Heroku gem doesn’t create any conflicts then you should be just fine. I’ve found a slight annoyance having to switch rvm aliases in order to run heroku commands. However, I find it more important that I can run the gems that the Rails project needs without letting my local dev setup get in the way.

blog comments powered by Disqus