Back to home

Rails Entity-Relationship Diagrams main image

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

Summary

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

@dennisokeeffe92
  • Melbourne, Australia

Hi, I am a professional Software Engineer. Formerly of Culture Amp, UsabilityHub, Present Company and NightGuru.
I am currently working on workingoutloud.dev, Den Dribbles and LandPad .

1,200+ PEOPLE ALREADY JOINED ❤️️

Get fresh posts + news direct to your inbox.

No spam. We only send you relevant content.