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:
</p>
class LineItem < ActiveRecord::Base belongs_to :product
- Schema as of Sun Feb 26 21:58:32 CST 2006 (schema version 7)
#- id :integer(11) not null
- quantity :integer(11)
- product_id :integer(11)
- unit_price :float
- order_id :integer(11)
#</code></pre></notextile>
When the schema is updated, the comment is updated to reflect the new schema.
Install it with the plugin script:
script/plugin install http://svn.pragprog.com/Public/plugins/annotate_modelsRun it with a custom rake task:
rake annotate_models
Check out the caveats in the README.
Thanks for sharing Dave.