Back to articles
My Favorite Rails Productivity Gem: annotate_models

My Favorite Rails Productivity Gem: annotate_models

via Dev.toZil Norvilis

Very often I find myself working inside a Rails model, and I need to write a validation or a custom method. But I suddenly forget the exact name of my database column. Is it first_name or just name ? Is the status an integer or a string ? Usually, to find this out, you have to open your db/schema.rb file, search for the table, and read the columns. It is not too hard to do it, but when you do it 50 times a day, it gets very annoying. This is where the annotate_models (usually just called annotate ) gem comes in. It is one of the first gems I add to any new Rails project. It automatically writes a commented-out summary of your database table right inside your model file. Here is how to set it up and use it in 3 easy steps. STEP 1: Installation First off, let's install the gem. We only need this in our development environment, because it just generates text comments for us developers to read. It doesn't do anything in production. Add the following to your Gemfile: group :development do g

Continue reading on Dev.to

Opens in a new tab

Read Full Article
8 views

Related Articles