Annotate - Adding Table Columns to Model File Automatically
Adding table column comments to a model file can be a chore, especially making sure they’re kept up to date as your schema changes over time which is especially important since out of date information is worse than no information at all. This is where Annotate comes in.
Annotate is a gem that will automatically add model information to a top level comment to each model in your project. It does this using your schema file and automatically updates the comments when you update your schema file so your model will always have accurate information.
Along with attributes it will also have information on column restraints and any indexes on your model.
It will also add this information to your specs and factories.
To install annotate run
gem install annotate or add
gem 'annotate' to your gem file and run
Adding comments to existing models
To update your existing files run
annotate in your console. This will add annotations to all your existing model, spec, and factory files.
# == Schema Information # # Table name: foos # # id :integer not null, primary key # name :text # created_at :datetime # updated_at :datetime # class Foo < ActiveRecord::Base end