Annotate your Rails model

I just discovered this handy little gem called annotate. Run it and it’ll insert a comment in all of your model files at once, outlining the schema. This is incredibly convenient when working with your Rails models to be able to see the data and types right there in the top of the file.

Here’s what my Noober (/app/models/noober.rb) model looks like by default:

Spartan as always. Let’s give ourselves something to look at with the annotate command. First, include annotate in your Rails 3 project in the Gemfile:

Run the install command to update your gems:

Run it from within your project directory:

And the result should look something like this in your models:

Awesome! Now I can see quickly which parts of the model I need to work with and add my code without having to peek at the database:

Works well for me!

Leave a Reply

Your email address will not be published. Required fields are marked *