Rails Map
🌐 Homepage | 📦 RubyGems | 🐙 GitHub
Automatically generates interactive API documentation for Rails by mapping routes, controllers, and models. Zero configuration—just install and go.
- Routes - All routes grouped by controller with HTTP methods, paths, and route names
- Controllers - Separate page for each controller with detailed route information
- Models - Separate page for each model with columns, associations, validations, and scopes
Installation
Add this line to your application's Gemfile:
gem 'rails_map'And then execute:
bundle installQuick Setup (With Authentication - Default)
Run the installer:
rails g rails_map:installSet environment variables (optional):
export RAILS_MAP_USERNAME=admin
export RAILS_MAP_PASSWORD=your_secure_passwordOr add to .env file:
RAILS_MAP_USERNAME=admin
RAILS_MAP_PASSWORD=your_secure_password
This automatically:
- ✅ Creates
config/initializers/rails_map.rbwith authentication enabled - ✅ Mounts the engine at
/rails-map - ✅ Adds
/doc/apito.gitignore - ✅ Uses default credentials (admin/password) if ENV variables not set
Start your server and visit http://localhost:3000/rails-map - you'll be prompted to login!
Setup Without Authentication
If you don't want authentication (development only recommended):
rails g rails_map:install --skip-authThis will:
- ✅ Create the configuration file (auth disabled)
- ✅ Mount the engine at
/rails-map - ✅ Add
/doc/apito.gitignore
Start your server and visit /rails-map - no login required!
Usage
Live Documentation (Recommended)
Mount the engine in your config/routes.rb:
mount RailsMap::Engine, at: '/rails-map'Then visit http://localhost:3000/rails-map in your browser to see live documentation.
Static HTML Generation
Run the following rake task to generate static HTML documentation:
rails doc:generateThis will generate HTML documentation in doc/api/ directory.
Open Documentation in Browser
rails doc:openClean Generated Documentation
rails doc:cleanConfiguration
Create an initializer config/initializers/rails_map.rb:
RailsMap.configure do |config|
# Output directory for generated documentation
config.output_dir = Rails.root.join('doc', 'api').to_s
# Application name displayed in the documentation
config.app_name = 'My Application'
# Theme color (any valid CSS color)
config.theme_color = '#3B82F6'
# Include timestamp columns (created_at, updated_at) in model documentation
config.include_timestamps = true
# Include model validations in documentation
config.include_validations = true
# Include model scopes in documentation
config.include_scopes = true
# Authentication - Protect documentation with authentication
# Uses environment variables: RAILS_MAP_USERNAME and RAILS_MAP_PASSWORD
# Defaults to username: admin, password: password
config.authenticate_with = proc {
RailsMap::Auth.authenticate(self)
}
# Option 2: Devise
# config.authenticate_with = proc {
# authenticate_user!
# }
# Option 3: Custom logic
# config.authenticate_with = proc {
# redirect_to root_path unless current_user&.admin?
# }
endFeatures
- 📱 Responsive Design - Works on desktop and mobile
- 🎨 Customizable Theme - Change the primary color to match your brand
- 🔗 Interlinked Pages - Easy navigation between related models and controllers
- 🏷️ HTTP Method Badges - Color-coded badges for different HTTP methods
- 📊 Statistics Dashboard - Quick overview of your application structure
- 🔍 Association Type Badges - Visual distinction for different association types
- 📝 API Parameter Detection - Automatically extracts and displays parameters for each route
- Path parameters (
:id,:user_id, etc.) - Query parameters for GET/DELETE requests
- Request body parameters for POST/PUT/PATCH requests
- Type inference (string, integer, boolean, datetime, etc.)
- Required/optional indication
- Parameter location (path, query, body)
- Path parameters (
Development
After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests.
To install this gem onto your local machine, run bundle exec rake install.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/ArshdeepGrover/rails-map.
License
The gem is available as open source under the terms of the MIT License.