Thursday, May 27, 2010

Tweaking on Rails 3.0: #1 Callback Blocks


There are plenty of articles about the big changes in Rails 3, so I feel motivated to comment on the small ones.
You might be familiar with using a block with a callback. Let's define an article model for our awesome new blogging software. It defines a default title for a newly created article:



Notice that we must pass the new article to the block. In Rails 3, the block is evaluated within the scope of the new instance, so we can change it to look like this:


Extremely minor, but I find myself using block callbacks more often because of it.

0 comments: