Outsmarted by Edge Rails
One of the cool things about starting new applications based on Edge Rails (as opposed to a stable gem version) is that I get access to all the awesome new features right away. Sure, there are a few panic moments when I get hit with unexpected bugs, and I don’t use SVN externals to link to the Rails trunk any more [1], but every now and then, I’m pleasantly surprised by something that I hadn’t previously read about.
I was in the process of adding counter_cache support to an application which had some very deep parent-child relationships, and I needed to generate a migration to add the _count column.
script/generate migration add_widgets_count_to_product
Imagine my surprise when I opened up the newly-created migration file in Textmate, and saw the following:
class AddWidgetsCountToProduct < ActiveRecord::Migration
def self.up
add_column :products, :widgets_count, :type, :null => :no?, :default => :maybe?
end
def self.down
remove_column :products, :widgets_count
end
end
After a little digging, I found this in the Rails Trac: Automatically generate add/remove column commands in specially named migrations. It would seem that Ryan Davis has put together some REGEX magic along with some meta-programming to help out people like me who give their migrations very literal names about what the migration will do.
This is a great little timesaver, but now it has me wondering what other neat features have slipped without my noticing them. It looks like it may be time for me to add the Trac timeline RSS feed to my reader, so I can keep a sharper eye out for these sorts of treats.
[1]: These days, when I start a new project, I freeze a version of edge Rails into the application, that way, I get most of the cutting edge features, and a much lower chance of introducing unexpected trouble every time I type ‘svn up.’ Periodically, I review what’s changed in trunk since I started, and if there’s some gotta-have-it feature, I’ll re-freeze.
Comments
-
This is precisely why I have avoided edge Rails for so long. I'm now on a project where we are on the edge. I really enjoy the new features, but I'm constantly wondering what I'm doing a little smellier than I have to. I wanted to avoid being inundated with the Trac feed, because honestly a large majority of it won't be applicable for me in the near future. So I'll either forget it anyway, or stress about finding a manner to try to remember it. And when I know something is available, but can't quite remember how to do it/use it. Most. Frustrating. Thing. Ever.
-
The comment above was supposed to have paragraphs. :)
