Annotate - Another development helper Gem for ROR

Annotate gem helps in adding routes as comments in rout file and table schema in model.

Annotate - Another development helper Gem for ROR

Ruby on Rails is faster in way of development as compared to many other frameworks. It’s Convention over Configuration methodology, the code generators already help a lot in getting things done quite fast.

Problem and Solution:

Extensions in code editor and some development gems also help a lot in speeding up the development process. One of such gems is Annotate. It resolves a problem that we ROR developers encounter is that we have to do rails routes every time we want to check the routes generated by routes.rb file. It would be great if we can get all routes generated in routes.rb file.

Similarly, we have to check the schema for a particular model to see what columns and their indexes are present in the database for that model. It would be great if all the columns and their indexes' data available inside the same model file so that we can work better while remaining in the same file we are working on. The same is the issue for RSpec Factories we work on.

Annotate Gem resolves all the above-mentioned issues.

Installation and Usage:

To install annotate to your project, add it to your Gemfile like below in development group as this is helper for developers.

Add Annotate To Gemfile
Add Annotate To Gemfile

Then run bundle install. After this run in terminal rails g annotate:install.

Now when you run migration models will get updated automatically. And when you run rails routes route file will get updated respectively.
To update models manually you can run annotate --models and to update routes annotate --routes or simply annotate to update both.

Your model now will look like below, check you have schema’s complete information in comments in model file:

Model final view
Model final view

Similarly, the route file would look like:

Routes file final view
Routes file final view

There are many other options to annotate gem, which you can look into its documentation.

Happy Coding!