Tuesday, February 6, 2007

Rails 1.2.2: SQLite3, gems, singular resources

Posted by David

It’s time for another minor update to Rails 1.2. This was primarily prompted by a change in the API for SQLite between version 3.3.7 and 3.3.8+, which left the Rails database adapter for dead by the road side. But with this release and Jamis Buck’s sqlite3-ruby gem at version 1.2.1, we’re back in business on all versions of SQLite3.

Second, we’re now depending on RubyGems 0.9.0 and above. This will fix the deprecation messages for require_gem (the new method is just gem) and will restore rake rails:freeze:gems to working order. So be sure to update to the latest RubyGems before installing. That’s done with “gem update —system”.

Finally, we’ve decided to throw in a few goodies along with the fixes described above and the rest of the bug reparations in this release. Singular resources, for example, allow you to model singleton resources within the scope of the domain. The common example is user.application.com/account. That’s now modeled with:

map.resource :account

…and routes accordingly:

GET /account => AccountController#show GET /account/new => AccountController#new GET /account;edit => AccountController#edit POST /account => AccountController#create PUT /account => AccountController#update DELETE /account => AccountController#destroy

Note that the controller is also singular, not plural as is usually the case when using map.resources.

We’ve also brought over the enhancement to :conditions in Active Record that’ll allow you to pass in ranges and get them automatically converted to BETWEEN statements. Like:

Student.find(:all, :conditions => { :grade => 9..12 })

…which then becomes:

SELECT * FROM students WHERE grade BETWEEN 9 AND 12”

This is a recommended upgrade for everyone running 1.2.x (and a reminder that if you’re not yet on Rails 1.2.x, you won’t be getting bug fixes automatically and have to backport them yourself). It’s a drop-in replacement requiring no changes to applications running 1.2.×.

Enjoy!