Rails 3.1.0 was released on 8/31/2011, and as such marks a great day for the Rails community. For a while Rails felt stagnant (think 2.3.11 to 3.0.1RC) and so this is something I’ve been looking forward to. As I’ve been using Rails 3 for over a year now, and I’ve been following along in the change sets, I wanted to point out some of the features I think are really going to be game changers.
Sprockets, and the Asset Pipeline
Although it requires Ruby 1.9x to run, HTTP streaming has finally been added. Part of the confusion I often hear about Rails is why this feature was not there from day one. To be honest, I’m not sure but my hunch is that it didn’t make sense in a prototyping stage to have to stream content. Further, it’s very very error prone compared to building your response and then shipping it over (i.e. if computational errors occur mid stream you’re dead in the water and the page will never finish loading). Further, Ajax helped mitigate this need by loading a light HTML shell and then using asynchronous calls to fetch your users’ data. At any rate, I’m very excited for this feature because the last two years of PHP coding has had me used to buffering output and I really do see the value in being able to use streaming to show progress without making lots of asynchronous calls.
ActiveResource now defaults responses to JSON, as opposed to XML.
Rails 3 comes with a quick and easy way of doing Basic Authentication (Username/Password) in your Controllers. Read up on Base.http_basic_authenticate_with – Check out the example here
Pluralize Names for Models
Yup! You can now set, on specific models, whether you want them pluralized or not. From within your controller class you’d set:
self.pluralize_table_names = false
You now have a model attribute
has_secure_password that will take care of password hashing/encryption.
As a concluding note on this short article please take some time to look over their very readable and friendly documentation on changes: Rails 3 ActiveModel Changes