Rails 2.1 is making my life easier.

I realized today it’s been nearly a month since I’ve posted an update to this blog. I blame my current projects and the additional time I’ve spent on professional development this past month. 

I’ve taken quite a bit of time over the past month to pick apart and play around with the new features in Rails 2.1. I won’t go into detail about every new feature, you can read all the juicy details here

I do want to quickly mention a very nice new feature in ActiveRecord 2.1, the ability to read if a record or a specific attribute in a record has changed. This make validation loops easier to write and minimizes round trips to your database if the application is engineered and tested accordingly. Take a look at the example below and checkout http://www.rubyonrails.org for more details on the 2.1 update. 

 
article = Article.find(:first)
article.changed? #=> false

# Track changes to individual attributes with
# attr_name_changed? accessor
article.title #=> "Title"
article.title = "New Title"
article.title_changed? #=> true

# Access previous value with attr_name_was accessor
article.title_was #=> "Title"

# See both previous and current value with attr_name_change accessor
article.title_change #=> ["Title", "New Title"]

Tags: , ,

Comments are closed.