orrtzw
Last Updated: February 25, 2016
·
5.811K
· andy_kif

Generating Entity-Relationship Diagram for Ruby on Rails

As a Rails developer, I used to directly map my business models into code within AR instances but as the number of models grows, it become difficult to have a clear idea of the whole picture.

I discovered rails-erd gem and started to use it intensively to have a snapshot of the models relations and associations inside the app by generating an ERD from your models.

rails-erd automatically generates a PDF with your app models graph using graphviz library.

Here's how to use it

Installation

Install graphviz (if not yet)

sudo apt-get install graphviz

Add the gem

In the project gemfile add

group :development do
  gem 'rails-erd'
end

Then execute cd PATH_OF_THE_PROJECT && bundle install

Using it

It's as simple as a bundle exec rake erd and it will generate a PDF file in the root of the app.

See what it can do here in the erd gallery

Say Thanks
Respond

5 Responses
Add your response

12452
5366fc271140fdb8fd08703d082ee4ab

cool feature, thx!

over 1 year ago ·
12465
62c329f4dbd904bbff9ac34fbc0f53f6

You can use brew install graphviz on OSX, everything else remains the same.

over 1 year ago ·
12493

Thanks @erebusbat for adding this, I'm mainly on debian stack so any extra for other OS flavours are welcome !

over 1 year ago ·
13094
9b5ac8fa5da2032f33a89e4e14110c04

This is amazing! Thanks YOU!

over 1 year ago ·
16268
6eb222189e8c76b33976df0fecfff679

If you are in Mavericks you will probably run into an issue where the pdf generation hangs, if you do then this will help!
- rake erd filetype=dot
- dot -Tpdf erd.dot > erd.pdf

Source: https://github.com/voormedia/rails-erd/issues/63

over 1 year ago ·