Annotated models

Ever working with a model and you forget what all of its columns are? Ever find yourself with your schema.rb open in a separate window so you can see what the structure is of your tables?

Dave Thomas, of Rails Pragmatic Studio fame (among a brazillion other things), hacked up a plugin that adds a comment block to the top of all of your model classes documenting the current schema for the given model. It ends up looking something like this:

  1. Schema as of Sun Feb 26 21:58:32 CST 2006 (schema version 7)
  2. id :integer(11) not null
  3. quantity :integer(11)
  4. product_id :integer(11)
  5. unit_price :float
  6. order_id :integer(11)
class LineItem < ActiveRecord::Base belongs_to :product

When the schema is updated, the comment is updated to reflect the new schema.

Install it with the plugin script:

script/plugin install

Run it with a custom rake task:

rake annotate_models

Check out the caveats in the README.

Thanks for sharing Dave.

blog comments powered by Disqus