LoginSignup
0
0

More than 1 year has passed since last update.

Rails annotateについて

Posted at

annotateとは

annotateとはmodelやテストのファイルに
schemaなどにあるデータベースの情報などをコメントとして出力させるためのgemです。
schemaを確認する手間が省けるメリットがあります。

導入方法

まず初めにGemfileの中に以下のように追記します。

group :development do
  gem 'annotate'
end

その後にbundle installで導入完了です。

annotateの実行

migrationを実行した時に、schema(データベース)の情報を
ファイルにコメントを出力させたい時には以下のコマンドを実行します。

$ bundle exec rails g annotate:install
app/model/memos.rb

# == Schema Information
#
# Table name: articles
#
#  id         :integer           not null, primary key
#  body       :text
#  title      :string
#  created_at :datetime         not null
#  updated_at :datetime         not null


#省略


class Memo < ApplicationRecord

end



factories/memo.rb

# == Schema Information
#
# Table name: memos

#  id         :integer           not null, primary key
#  body       :text
#  title      :string
#  created_at :datetime         not null
#  updated_at :datetime         not null

FactoryBot.define do
  factory :memo do

    #省略

  end
end

のようにコメントを出してくれます。

こちらの都合でもっと詳細に書くことはできませんが、
他のもルーティング情報を書き出したり、手動で 実行したり、コメントを消したりできる
コマンドがあるので下の資料から調べてみてください。

●参考資料
https://tech.mof-mof.co.jp/blog/rails-annotate/#annotate%E3%81%A8%E3%81%AF
https://qiita.com/kou_pg_0131/items/ae6b5f41c18b2872d527

0
0
0

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
0
0