Generate Mermaid ER diagrams from your Rails model associations and schema.
Unlike schema-only tools, Rails Modeler reads has_many, has_one, belongs_to, and has_and_belongs_to_many declarations via Rails' Reflection API, and extracts attributes from db/schema.rb.
Add to your Gemfile:
gem "rails_modeler", group: :developmentThen run:
bundle installGenerate the diagram:
rake rails_modeler:generateThis writes a .mmd file (default: docs/schema.mmd) and prints the diagram to stdout.
Create an initializer at config/initializers/rails_modeler.rb:
RailsModeler.configure do |config|
config.excluded_models = ["ActiveStorage::Blob", "ActiveStorage::Attachment"]
config.output_path = "docs/er_diagram.mmd"
config.show_attributes = true
config.title = "My App Schema"
end| Option | Default | Description |
|---|---|---|
excluded_models |
[] |
Model names to omit from the diagram |
output_path |
"docs/schema.mmd" |
Where to write the .mmd file |
show_attributes |
true |
Include column attributes in entity blocks |
title |
"Schema" |
Diagram title |
erDiagram
Author {
integer id PK
string name
}
Article {
integer id PK
string title
integer author_id FK
}
Author ||--o{ Article : "has_many"
belongs_to(including polymorphic)has_many(includingas:polymorphic)has_onehas_and_belongs_to_many
Bidirectional associations are automatically deduplicated.
bundle install
bundle exec rspecMIT License. See LICENSE.txt.