Things I had to fix for Rails 2.2.2

The new features in Ruby on Rails 2.2.2 have been well documented, and I’m looking forward to using several of them on WhatYouAte.com. If you’re reading this you probably are too.

However, if you’re upgrading an existing project and you’re sticking with official releases (as opposed to edge Rails) like I am, your code probably needs some tweaking to work with Rails 2.2.2. Mine certainly did. Although there were a lot of failed tests with ugly stacktraces, there were only a few API changes in Rails that needed to be accomodated to fix them all. Here’s a list of the changes that broke my app, and what I had to do to get it working again.

TextHelper.truncate no longer allows you to supply the length parameter as a second argument. You have to use truncate(somestring, :length => 20) instead of truncate(somestring, 20).

I was getting an error that looked like this:

The line in question is:

The problem is that the simply_helpful plugin’s behavior is now built-in; just delete the whole vendor/plugins/simply_helpful directory if you were using it, and any existing code that depends on simply_helpful’s API should work again.

I was using the tztime and tzinfo_timezone plugins, which are no longer needed now that time zone support is available via Time.zone in Rails 2.2. Delete the plugins, upgrade the tzinfo gem to 0.3.12 or uninstall any older version of it, and search for TzTime instances in your code and replace any of the occurences of Time.at(some_tztime_variable) that you had been using. TzInfo is still useful in cases such as this:

But since you can now embed the time zone information in a Time instance, you don’t need TzTime objects anymore.

I was using a nice hack from Technoweenie, to allow me to validate forms using the familiar ActiveRecord model validations API even if those forms were not backed by a database table (sometimes the UI just doesn’t look anything like the data model, y’know?). It broke, and I was unable to find any solutions from anyone else, so I wrote my own: EphemeralModel, for Rails 2.2.2 form validation without a DB table.

I was using ActiveRecord::Errors.default_error_messages[:invalid] in a few model validators, which is now deprecated because it’s not internationalized. The new way to ask for the same string in the currently configured language is: I18n.t(:invalid, :scope => 'activerecord.errors.messages')

Finally, the app wouldn’t start because it wants a :secret option to config.action_controller.session in config/environment.rb. I came up with something sufficiently random and now it’s fine.

I’d just like to make one last comment about this: having thorough automated tests is a huge time and sanity saver during this process. If you’re not close to 100% test coverage on your current Rails project, then your house is on fire and you need to address that immediately. Even as I write this in late 2008, I’m talking to prospective clients about contracting work, and some of them don’t do automated testing at all(!). Unless you’re in a mad dash for a demo that will save the company from financial collapse, having automated tests that verify that your code works should be priority #1. Upgrades can wait.

8 thoughts on “Things I had to fix for Rails 2.2.2”

  1. hey,
    I’m also getting a lot of “ActionView::TemplateError: wrong number of arguments” from my rspec test suite… but I’m not using the simply_helpful plugin at all. Any ideas what method changed in rails 2.2 with this template argument issue?

Leave a Reply

Your email address will not be published. Required fields are marked *