Rails 2 update coming soon

A heads-up if you use Ruby on Rails: We’re going to be upgrading the default version on our servers to 2.0.2 soon. We want to give you plenty of notice, because when we tried upgrading some older test applications, they didn’t work without changes.

We’ll get to the problems below, but first, let’s consider how Rails versions work. One nice Rails feature is that there can be multiple versions of Rails on the server, and you can choose to “bind” your application to a particular Rails version. In fact, new Rails apps are “bound” to the default Rails version that’s on the server when you create the app, which is good for stability. Even when we update Rails, your app continues using the same old version until you change it.

You actually get even more control than that: you can “freeze” your Rails application to any version you like — even versions newer than the ones on the server. That’s the main reason we haven’t been in a hurry to update to Rails 2 systemwide; you can easily update your Rails app to 2.0.2 now if you want.

So if you’ve created your own app, and you haven’t removed the configuration line that binds Rails to a particular server version, nothing we do will affect you. Until you change your Rails version, you’ll continue using 1.2.6 (or whatever version you’ve chosen). However, some people may have installed third-party Rails apps that aren’t bound to a particular version and don’t have a frozen copy of Rails, and those would be affected by an upgrade.

Which brings us to the problems we saw when upgrading some old test applications. After changing the Rails version, they started displaying a “500 Internal Server Error” message. The Rails log file shows:

Status: 500 Internal Server Error
A secret is required to generate an integrity hash for cookie session data. Use config.action_controller.session = { :session_key => "_myapp_session", :secret => "some secret phrase of at least 30 characters" } in config/environment.rb

Hmmm, all right. So we need to add a line like this to the “Rails::Initializer.run” section of the “config.rb” file, with some random text like so:

config.action_controller.session = { :session_key => "_myapp_session", :secret => "b836b5a8578d3c74a5dbd0956102784f864e7b67" }

That fixed the 500 error. (By the way, if you’re looking for a good way to generate random strings, try “head /dev/urandom | sha1sum” on a command line.)

We then had a couple of other minor issues. The first was that Rails 2 really doesn’t want to work without a valid database. If your Rails app doesn’t use a database, that’s apparently “not a supported configuration” and you’ll need to either create a fake database or make some code changes. The second issue was that some things that have been deprecated for some time (such as “render_text”) have been completely removed; if you’ve been putting off making those changes, now’s the time.

Anyway, if you’re using Rails, you probably want to test your application for compatibility now. You can do that at any time by “freezing” it to version 2.0.2. If it doesn’t work, just freeze it back to 1.2.6 while you fix the problems.

(We’ll post another blog entry when we actually upgrade Rails, of course.)

3 Comments

  1. Was this roll out ever completed? As of this comment, I’ve checked and we still only have Rails 1.2.6 on our box. What’s more, we don’t seem to even have gems installed. Thanks.

  2. We decided to wait and upgrade to Rails 2.1 instead, which will be happening soon. But part of the point of our post was that even if we have a conservative, non-cutting-edge default install, you don’t need to wait — you can choose any version of Rails you want. See our freezing Rails page for details.

    Regarding gems, the standard Rails gems (actionmailer, etc.) are installed (you can type “gem list” to see them). You can also install your own additional gems locally, but suggestions for additional systemwide gems are welcome.

  3. Thanks for your help, I’ll be looking into “freezing” my app to 2.1 (which I already have on my development computer here) and working off of that.

    With regards to gems, I was actually typing gems list instead of gem, something I realized about an hour after posting the previous comment. Boy does that make me feel like an idiot.