Working in Rails 2 & 3 with rvm
I had wanted to play with Rails 2 a bit, without breaking any of the Rails 3 apps I’m working on. I use rvm anyway, so I thought it would be pretty straightforward. I found instructions for setting it up, but ran into a couple snags.
First I installed Ruby 1.8.7 and created a gemset.
$ rvm install 1.8.7 $ rvm use 1.8.7 $ rvm gemset create rails2 $ rvm use 1.8.7@rails2
Then installed rails 2.3.11:
$ gem install rails --version 2.3.11
The first problem I ran into was that rvm had put rake 10.0.4 in the global gemset for ruby 1.8.7. This caused an error when running rake tasks:
ERROR: 'rake/rdoctask' is obsolete and no longer supported. Use 'rdoc/task' (available in RDoc 2.4.2+) instead.
To fix this:
$ rvm use 1.8.7@global $ gem uninstall rake $ rvm use 1.8.7@rails2 $ gem install -v=0.8.7 rake
It was also using the latest rubygems. This caused another error when running the gems:install rake task:
undefined method `name' for "actionmailer":String
To fix:
$ rvm rubygems 1.6.2
Now you should be able to play. You may want to brush up on the differences between Rails 2 and 3 if it’s been a while.
$ rails r2test $ cd r2test
[uncomment the sqlite3-ruby line in config/environment.rb]
$ rake gems:install $ script/generate scaffold User name:string $ rake db:migrate $ script/server
Voilà.
Pro tip: set up an rvmrc for your Rails 2 projects so rvm automatically loads the correct ruby version & gemset when you cd into the directory.
$ rvm rvmrc create 1.8.7@rails2 $ rvm rvmrc trust