LoginSignup
24
25

More than 5 years have passed since last update.

【Rails】ER図作成

Last updated at Posted at 2019-04-05

RailsでER図を作成する便利なライブラリのインストールと使い方

必要な各ライブラリをインストール

  • rails-erd 【gem】
  • graphviz

必要なのはこの2つ
※ homebrewが必要なので事前にインストール

rails-erdのインストール

Gemfileに追記

Gemfile
group :development do
...
  gem "rails-erd" # 追加
...
end

できたら下記コマンドでインストール

$ bundle install

graphvizのインストール

$ brew install graphviz

これで必要なライブラリのインストールは終わり

ER図出力

下記コマンドを使用するとカレントディレクトリにerd.dotファイルが生成される

$ bundle exec erd --inheritance --direct --attributes=foreign_keys,content --filetype=dot

dotファイルを閲覧できる形式に変換

  • pngに変換
$ dot -Tpng erd.dot -o erd.png
  • pdfに変換
$ dot -Tpdf erd.dot -o erd.pdf
24
25
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
24
25