データベースのスキーマ情報をmodelファイルに追加するgem、annotateの使い方
annotateの使い方
各モデルのスキーマ情報をファイルの先頭もしくは末尾にコメントとして書き出してくれるgem。
例えば、app/model/user.rb ファイルの最初にテーブルのカラム等を記述してくれる。
① Gemfileに追加
gem 'annotate'
② gemとdbを更新。
$ bundle install $ rails g annotate:install $ rails db:migrate
③ スキーマ情報が書き出される。
# == Schema Information # # Table name: users # # id :integer not null, primary key # crypted_password :string # email :string not null # salt :string # created_at :datetime not null # updated_at :datetime not null # # Indexes # # index_users_on_email (email) UNIQUE # class User < ApplicationRecord end