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
Written by Andy Kifer
Related protips
5 Responses

cool feature, thx!

You can use brew install graphviz
on OSX, everything else remains the same.
Thanks @erebusbat for adding this, I'm mainly on debian stack so any extra for other OS flavours are welcome !

This is amazing! Thanks YOU!

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