1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Railsの「annotate」gemが最高すぎる件

Posted at

環境

  • Docker version 18.09.2
  • Ruby 2.4.5
  • Rails 5.0.0

なぜ書いたのか

「あれ、テーブルってどんな構造してたっけ❓」 っていう時がかなりあった。

今まで確認する時は、

  1. DBに入る
  2. コマンドぽちぽち入力
  3. DB抜ける

上記3点のプロセスだったのが、

  1. Modelのrbファイル確認

annotateをインストールするだけでここまで短縮できることに感動したから

導入、実装

1.Gemfileに追記

Gemfile
group :development do 
  gem 'annotate' 
end

※基本的に開発環境でのみ使用するので、development内に書く

2.gemをインストール

ターミナル
$ docker-compose build

3.gemの実行

ターミナル
$ docker-compose exec web bundle exec annotate

これでModelを確認すると、下記のような感じでコメントアウトでテーブルの構造が!すごい!
スクリーンショット 2019-05-12 20.54.35.png

ただこれだとテーブルを作成、更新するたびに実行しなければならないので、
migrationをトリガーに実行するように設定ファイルを生成

ターミナル
docker-compose exec web bundle exec rails g annotate:install

これでmigrationの度にannotateが実行されるように👌

おまけ

routeにも適用できるらしいのでやってみた

ターミナル
$ docker-compose exec web bundle exec annotate --routes
スクリーンショット 2019-05-12 21.17.53.png

参考

https://qiita.com/tsuchinoko_run/items/9bcc15e8992cb237e08a https://www.udemy.com/share/1014LIB0sacllTQ3s=/
1
0
6

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?