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
![](https://coderwall-assets-0.s3.amazonaws.com/uploads/user/avatar/122408/none.jpg)
cool feature, thx!
![](https://coderwall-assets-0.s3.amazonaws.com/uploads/user/avatar/76580/62c329f4dbd904bbff9ac34fbc0f53f6.png)
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 !
![](https://coderwall-assets-0.s3.amazonaws.com/uploads/user/avatar/99818/2153691.png)
This is amazing! Thanks YOU!
![](https://coderwall-assets-0.s3.amazonaws.com/uploads/user/avatar/116470/6eb222189e8c76b33976df0fecfff679.jpg)
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