Blog

Upgrading Rails 1.2.6 -> 2.3.4

Yes, it's pretty sad that I still have a few sites running on 1.2.6. There's been plenty of good articles out there about the various steps you need to take to upgrade your app. Here's a quick rundown of some of the gotchas I ran into during this most recent upgrade for an old client.

No More acts_as_list

This one is easy:

ruby script/plugin install acts_as_list

File Column

Back in the day this plugin was the shiznet. Sure there are lots of newer (and better) implementations (try Thoughbot's Paperclip). But if you are lazy (like me) the file column plugin still works. However, their code relies on what was just the plain vanilla Inflector module. You have to go in and replace all mentions of Inflector with ActiveSupport::Inflector.

Paginate

Pagination is another dead beast. Mislav's will_paginate is the de-facto standard it seems these days. Here's a couple of sample diffs of what I had to do in my admin controller's and views to swap it out.

Controller:
-    @project_pages, @projects = paginate :projects, :per_page => 30, :order => sort_clause
+    @projects = Project.paginate(:page => params[:page], :per_page => 10, :order => sort_clause)
View:
-<%= render :partial => 'layouts/paginator', :locals => { :paginator => @project_pages } %>
+<%= will_paginate(@projects) %>

Easy-peasy.

No Scaffold

This one is a little more of a pain. I didn't want to muck around with writing a bunch of controller actions (like I said, I'm lazy!). So I used to have something like this in my controllers:

class Admin::ProjectsController < Admin::BaseController
  scaffold :project
  ...stuff...
end

To replace this I looked at a few alternatives. Active_scaffolding was probably the "right" approach, but I came across the plugin scaffolding and it seemed like the closest drop-in replacement.

ruby script/plugin install scaffolding

Now unfortunately that plugin hasn't been kept up to date with all of the latest Rails releases. In particular the plugin uses a template_exists? method that no longer exists in ActionController::Base anymore:

So if you get something like this

undefined method `template_exists?' for #meh

in your logs just add this method to the plugin. I added mine to the private section of scaffolding.rb just before the def render method

def template_exists?(path)
  self.view_paths.find_template(path, response.template.template_format)
rescue ActionView::MissingTemplate
  false
end

Closing Thought

Of course don't forget to

rake rails:update