Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
95 lines (64 sloc) 2.51 KB


Add a comment summarizing the current schema to the bottom of each ActiveRecord model, fixture file.

If you are using Object Daddy, it`ll annotate your example files too.

# == Schema Info
# Table name: line_items
#  id                  :integer(11)    not null, primary key
#  quantity            :integer(11)    not null
#  product_id          :integer(11)    not null
#  unit_price          :float
#  order_id            :integer(11)

 class LineItem < ActiveRecord::Base
   belongs_to :product
  . . .

Annotates geometrical columns, geom type and srid, when using SpatialAdapter or PostgisAdapter:

# == Schema Info
# Table name: trips
#  local           :geometry        point, 4326
#  path            :geometry        line_string, 4326


Note that this code will blow away the initial/final comment block in your models if it looks like it was previously added by annotate models, so you don't want to add additional text to an automatically created comment block.

* * Back up your model files before using... * *


From rubyforge:

sudo gem install annotate

From github:

gem sources -a
sudo gem install ctran-annotate


To annotate all your models:

cd /path/to/app

To annotate routes.rb:

annotate -r

More options:

Usage: annotate [options]
    -d, --delete                     Remove annotations from all model files
    -p, --position [before|after]    Place the annotations at the top (before) or the bottom (after) of the model file
    -r, --routes                     Annotate routes.rb with the output of 'rake routes'
    -v, --version                    Show the current version of this gem
    -m, --show-migration             Include the migration version number in the annotation
    -i, --show-indexes               List the table's database indexes in the annotation
        --model-dir dir              Annotate model files stored in dir rather than app/models


Released under the same license as Ruby. No Support. No Warranty.


Original code by:

Dave Thomas -- Pragmatic Programmers, LLC

Modifications by:

- Alex Chaffee - -
- Cuong Tran -
- Jack Danger -
- Michael Bumann -
- Henrik Nyh -
- Marcos Piccinini -

and many others that I may have missed to add.