HowFlow


http://pragdave.pragprog.com/pragdave/2006/02/annotate_models.html
pragprog.com This is actually a very old trick, because annotate_models is one of the older Rails plugins. On the other hand, I realized that only a few people have heard of it.

Share it!   Posted by aroedl aroedl 3 months ago

If you want to know how your database schema looks like, you have three options: connect to your database and do it with DESCRIBE table, check the file db/schema.rb or use the annotate_models plugin:


script/plugin install http://repo.pragprog.com/svn/Public/plugins/annotate_models

Now you just have to run the new rake task annotate_models:


rake annotate_models

Open one of your model files and you’ll see a new comment block that looks like this:


# == Schema Information
# Schema version: 53
#
# Table name: vendors
#
#  id         :integer(11)     not null, primary key
#  vclass     :string(255)
#  name       :string(255)
#  vid        :integer(11)
#  created_at :datetime
#  updated_at :datetime
#  creator_id :integer(11)
#  updater_id :integer(11)
#

You should run the rake task every time you do a migration to keep the annotation up-to-date. It’s trivial but very helpful. I couldn’t live without this plugin.

For more Rails tricks, click here



Please log in or sign up and vote for this trick if it was helpful for you.
Don't forget to subscribe to our RSS Feed RSS/Atom feed to get the latest tricks.