是否曾经在使用某个模型时忘记了它的所有列?是否曾经在单独的窗口打开 schema.rb
文件,这样就能看到表的结构?
Dave Thomas(以 Rails Pragmatic Studio 的名声著称,还包括其他无数的事情),破解了一款 插件,为所有模型类顶部添加了注释块,注释块记录了给定模型的当前架构。最终可能会显示类似内容
</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.