Last Updated: September 09, 2019
· 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


Install graphviz (if not yet)

sudo apt-get install graphviz

Add the gem

In the project gemfile add

group :development do
  gem 'rails-erd'

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

5 Responses
Add your response

cool feature, thx!

over 1 year ago ·

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

over 1 year ago ·

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

over 1 year ago ·

This is amazing! Thanks YOU!

over 1 year ago ·

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.pdf


over 1 year ago ·