Upgrading Rails2 -> Rails3

The past few months, among normal work stuff, I’ve been busy working to convert an old (5years and running) app from Rails 2.3.x to Rails 3 with the hope of finally getting to Rails 3.2 and Ruby 1.9.x.

It’s been a bit of an uphill slog, as you might imagine.

I’m going to start scribbling some of my notes here in the blog in a series of posts in hopes that others don’t rathole on the same issues that I struggled with.

Pre Rails3

After a chunk of reading online (much thanks to the airbnb post), I started by trying to update the codebase without updating Rails so that when I did move, I’d have as much of the simple stuff resolved in the Rails2 branch.

Step 1: rails_xss

I started by installing the rails_xss gem. This switches the default view generators to escape strings which is inline with what Rails3 views do.

I added to my Gemfile :
gem 'rails_xss'
gem 'erubis'

Thankfully, I had a pretty strong view test suite and was able to find and fix issues based on my test failures.

Step 2: Dump RAILS_ROOT

This was pretty much a search-replace task. Replace RAILS_ROOT with Rails.root

Step 3: include jQuery with noConflict

This app was still on PrototypeJS. It seems like it’s finally time to make the move. The first step is to simply get jQuery in the codebase with noConflict. This will allow me to convert, over time, the Prototype plugins and code to jQuery without having to move it all in one chunk.

This was pretty straight forward. Add the jQuery source from http://jquery.com/ and include it in my HAML layouts like so (at the top, before including prototype and other library js):

= javascript_include_tag "thirdparty/jquery-1.8.2.min.js"
= jQuery.noConflict();

With these mods, and getting my test suite sorted out, I was able to push out a new version still on Rails 2.3.x but much closer to being Rails3 ready that it was before these mods.

I’ll continue to add notes in subsequent posts.

References
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s