LoginSignup
0
0

More than 1 year has passed since last update.

annotate_modelsでmigrationの度に自動でアノテーションを作成させる方法

Last updated at Posted at 2022-03-17

環境

Ruby 3.0.2
Rails 7.0.2.3

Annotate models

モデルファイルなどに、↓のようなマイグレーションの内容を自動で書いてくれるツール

# == Schema Info
#
# Table name: line_items
#
#  id                  :integer(11)    not null, primary key
#  quantity            :integer(11)    not null
#  product_id          :integer(11)    not null
#  unit_price          :float
#  order_id            :integer(11)
#

class LineItem < ActiveRecord::Base
  belongs_to :product
  . . .

ここを参考に導入しました。

動かない

rails db:migrate

migration実行すると動作してくれるはずなのにアノテーションが書かれない。

解決

公式のREADMEを読むと、

To automatically annotate every time you run db:migrate, either run rails g annotate:install or add Annotate.load_tasks to your Rakefile.

と書かれてたので、そのとおり実行。

rails g annotate:install

無事に作成されました。
しっかりドキュメントにも目を通さないといけないですね。

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