Ruby on Rails: What a difference three years make.
I’ve been working on a major update of a project I originally completed in 2006–same basic interface, same basic functionality; new version of Rails. Specifically, I’m going from version 1.2.6 to 2.2.2.
So what’s happened since then that’s so useful? Two immediate things come to mind:
- REST: It’s amazing how many things just happen like magic when you’re developing Rails apps and you’ve accepted a REST-based architecture into your workflow, especially when using gems I’ve [mentioned i–s-for-ruby-on-rails.html) like restful_acl and nifty_generators. Before Rails, work I did in PHP that took a day now took a couple of hours in 2006. Now it takes about 30 minutes. If you still haven’t quite figured out why REST is a big deal, spend a little time viewing a Railscast or two or reviewing this (slightly dated) PDF tutorial, which is what really hammered the whole thing home for me. Seriously, if you’re using Rails (or any framework) and you’re not RESTful, you’re doing it wrong.
- named_scope: Perhaps the greatest thing to come to ActiveRecord since, well, ever. named_scope was introduced in Rails 2.1 and covered nicely in Railscast no. 108. What makes named_scope extra-awesome is how you can string them together to create rather complex SQL queries without resorting to any sort of custom code. named_scope has saved me with plugins/gems that don’t have key features I need (like being able to scope a user’s timeline events with timeline_fu) a few times, not to mention making it easier to DRY up quite a bit of ActiveRecord/database-related custom code.
And keep in mind: I’m still developing productional apps for Rails 2.2.2; I’ve barely even scratched what 2.3 does (or what Rails 3 will do).