LoginSignup
49
47

More than 5 years have passed since last update.

RailsでER図を生成するGem(rails-erd)

Posted at

RailsでのER図の自動生成について。

rails-erdというGemをCentOS6に入れる方法です。

「graphviz」というRPMを追加して、Gemで「rails-erd」をインストールする流れとなります。

# yum -y install graphviz
$ vi Gemfile
以下の行を追加
---------------------------
gem 'rails-erd', group: [:development, :test]
---------------------------
$ bundle install

ER図の生成は以下のコマンドから行えます。

$ rake erd
Loading application environment...
Loading code in search of Active Record models...
Generating Entity-Relationship Diagram for 3 models...
Done! Saved diagram to erd.pdf.

プロジェクト配下に「erd.pdf」というPDFファイルが出来ています。

内容は以下のような感じです。

スクリーンショット 2015-02-24 21.48.08.png

とても手軽なので、DBの依存関係の確認などさっと作れるので助かりますね。

他にもER図を作るものなど「railroady」というものがあるようです。

もう少し定義をしっかり書いた上で出力してくれるのもあると良いんですが。

49
47
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
49
47