🎉 I'm releasing 12 products in 12 months! If you love product, checkout my new blog workingoutloud.dev

Back to home

Rails Entity-Relationship Diagrams

This post will look into the rails-erd gem and how we can set it up to quickly visualize what our relationships in Rails look like.

Source code can be found here.

Getting started

In this particular post, we will make use of another project worked on demo-rails-associations in "Understanding Rails Associations" and "Through Rails Associations":

# Create a new rails project $ git clone https://github.com/okeeffed/demo-rails-associations.git $ cd demo-rails-associations # Add the gem $ bundle add rails-erd

After cloning the project, we just need to add the rails-erd gem and we are basically home and hosed.

Generating the diagram

At this point, all we need to do to output a diagram is to run bundle exec erd.

That will output a PDF file erd.pdf. The output will outline the following from the relationships we created in the previous posts:

Output ERD

Output ERD


Today's short post demonstrated how to generate the entity-relationship diagram for the Rails models using rails-erd.

Resources and further reading

Photo credit: pawel_czerwinski

Personal image

Dennis O'Keeffe

  • Melbourne, Australia

Hi, I am a professional Software Engineer. Formerly of Culture Amp, UsabilityHub, Present Company and NightGuru.
I am currently working on Visibuild.


Get fresh posts + news direct to your inbox.

No spam. We only send you relevant content.

Rails Entity-Relationship Diagrams


Share this post