Rails Nursery

I decided I give rbenv a shot. This change also means I have to find another way to separate rails gems from my standard ones. I’ll tell you why.

YMMV, but I have a couple of rails projects in my development directory. These are not necessarily on the same rails version. I have a 2.3, some 3.0, and some 3.1 rc used in my projects. Therefore I just can’t put all these gems into a single place. How my project selects the correct version of rails command? Hint: gem versioning is not a solution.

For my first problem, I found vendoring gems with style pretty useful.

In my opinion, rbenv fits perfectly to Ryan McGeary’s solution. Please put your project .rbenv file into source control.

Of course, from time to time I want to fire up a clean rails app for prototyping, and this is when I use gemsets. I could use rbenv-gemset from Jamis Buck too, but it’s just too much for my taste either.

My answer here is rails nursery (of course this applies to every ruby-related package, which requires some code generation):

gem install bundler
mkdir ~/Code/rails-nursery-3.1.0.rc6
cd ~/Code/rails-nursery-3.1.0.rc6
bundle init
echo 'gem "rails", "3.1.0.rc6"' >> Gemfile
bundle install --path=vendor --binstubs

That’s it. You switch to the nursery directory (in my case it’s ~/Code/rails-nursery-3.1.0.rc6), and you’ll have the minimum requirements for creating a new 3.1.0rc6 rails app:

cd ~/Code/rails-nursery-3.1.0.rc6
bin/rails new ~/Code/<project> --skip-bundle
cd ~/Code/<project>
echo 'vendor/ruby' >> .gitignore
echo 'vendor/rbx' >> .gitignore
bundle install --path=vendor --binstubs

Now you have a separate directory for all the gems you might not want in the future, and be honest: it’s much easier to get rid of this directory, than cherry-picking your installed gems.