Written by: steve ross on January 2nd 2008

Real quick. What's Gonna Break When I Upgrade to Rails 2.0.2?

I'm sure I don't know the answer to this question, but if you are upgrading an application from a 1.x version of Rails to 2.0.2, something sure will break. Guaran-effing-teed. So, let's see what those things might be (and these are just the ones I tripped over yesterday):

Session Store Changes

If you were using ActiveRecord based sessions, you can continue to do that. I recommend you change to the new cookie-based session store. Here's why:

Concerns? Everyone screamed that this was a gaping security hole. But the cookie data is 512-bit encrypted, and really how much sensitive material do you store in the session? If the answer is anything greater than "none," then you're the one opening the security hole.

Preparations: You have to generate a "secret" and put it in the configuration part of environment.rb. Here's a sample:


    Rails::Initializer.run do |config|
      # stuff...
      config.action_controller.session = {
        :session_key => '_my_app_session',
        :secret      => '241b740a2f480d9776e6ce0c36b51f9df46ecf1d25814cd03b4d14dbb6ba7cd92'
      }
      #stuff...
    end
  

This isn't too tricky. The session manaager is going to use this to name your session cookie and authenticate it. Suit yourself regarding naming and what sort of secret passphrase you want to choose. A random string of hex digits seems pretty ok to me.

The important thing that's been biting people is that if you don't change your session_key from the one you were using, a TamperedWithCookie exception will be raised for returning visitors. Not a seamless user experience so take care out there.

Dynamic Scaffolding Is Gone. Period.

Scaffolding is officially extracted to a plugin, and that's pretty keen because you can tell the "we didn't take any functionality away" story. But that's not the whole story. Scaffolding depends on other stuff that also has been extracted to another plugin, like "classic_pagination". Now, before I go any further down this path, let me emphasize.

DYNAMIC SCAFFOLDING IS GONE

But you can still do the script/generate scaffold person you've grown to know and love. You can also use one of the cool scaffold plug-ins like ActiveScaffold.

My recommendation is that you avoid scaffolding where possible. It's a great way to show CRUD in a hurry, but doesn't buy you much in the long term. If you want to DRY up common usage patterns, look at something like make_resourceful ("there's a post on nex3's blog":http://nex-3.com/posts/7). Sure, you have to code a few views, but what the hey?

Um, Did I Mention Pagination

If you are using pagination, guess what? Rails "classic pagination" has been extracted to a plugin (I think I already said that). I believe this is more of a death sentence for pagination, as evidenced by the comments in the code recommending will_paginate which you can pick up at svn://errtheblog.com/svn/plugins/will_paginate. It won't take you long to get in the swing of paginating err's way.

Singular Model, Plural Controller

Rails is opinionated, but it took a while before the opinion was unanimous regarding whether controllers should be singular or plural. The vote's in and your controllers should be plural if you want to play nice with map.resources. You can read more about this on "Ryan's Scraps":http://ryandaigle.com/; point is, Rails will like you better if you have PeopleController instead of PersonController.

Models, of course, are mappings to a single row of data, so they typically are singular. There is, of course, the ongoing debate regarding whether models should be so tightly coupled to the data layer, but we won't get into that. Rails will like you better if you have a Country model rather than a Countries model.

Capistrano Is v.2 Now, Too!

Well, sigh, no sense enduring the pain of a major version upgrade of your platform if you don't get the added joy of upgrading your deployment tools. If you aren't using Capistrano for deployment, then shame on you (kidding... it's just too easy). If you are using 1.x, there are some things to make note of. Look "here":http://www.capify.org/upgrade for information about upgrading, but for heaven's sake, deploy to a test server before you totally hose up your production box.

Semi-Wrapup

This is getting a little long and it's not supposed to be a list of changes -- more a few of the things that bite first when you move to Rails 2.x from an earlier version. If you decide to take an action-based Rails app and change it to a RESTful architecture, you'll be spending more time on that, but it's not a gotcha. You don't have to be RESTful. You'll just be made to feel guilty sitting in the corner all by yourself.

Well that's all for now. Hope this was useful and feel free to chime in any inaccuracies or glaring omissions.