rails/rails
Fun facts
Small bits of trivia about the Rails codebase.
The first commit was a single file from Basecamp (24 Nov 2004)
The first commit on main is dated 2004-11-24T01:04:44Z with the message "Initial". The very next commit, fifteen minutes later, says "Allow form_tag with no arguments (resulting in a form posting to current action) - Patch #236". The codebase has been moving at roughly that velocity for two decades.
The longest production file is the form helper
actionview/lib/action_view/helpers/form_helper.rb weighs in at 2,766 lines. It contains every text_field, select, date_field, submit, and form_with you've ever rendered. Twenty years of helper accretion lives here.
Honourable mentions:
actionpack/test/dispatch/routing_test.rb(5,343 lines) is the longest test file in the repo.railties/test/application/configuration_test.rb(5,308 lines) tests theRails::Application::Configurationclass. There's a lot to configure.
"Patch numbers" in early commit messages
Read the first few thousand commits and you'll see lots of Patch #236-style references. These weren't GitHub PR numbers — Rails predated GitHub. They were ticket numbers in the original Trac instance the project ran in 2004–2009.
Active Record is one third of the framework
Production Ruby in lib/:
- Active Record: 69,692 lines (≈36% of all production Ruby in the framework)
- Everything else combined: ~124,000 lines
Active Record contains adapters for four databases, an entire SQL AST library (Arel), an encryption subsystem, two query DSLs (where/find_by and Arel), the migration DSL, multi-DB connection routing, and seven kinds of association.
The tools/ directory is tiny but pivotal
Every component's bin/test is a one-liner that delegates to tools/test.rb, which is 17 lines:
$: << File.expand_path("test", COMPONENT_ROOT)
require "bundler/setup"
require "rails/test_unit/runner"
require "rails/test_unit/reporter"
require "rails/test_unit/line_filtering"
require "active_support"
require "active_support/test_case"
ActiveSupport::TestCase.extend Rails::LineFiltering
Rails::TestUnitReporter.app_root ||= COMPONENT_ROOT
Rails::TestUnitReporter.executable = "bin/test"
Rails::TestUnit::Runner.parse_options(ARGV)
Rails::TestUnit::Runner.run(ARGV)The runner itself lives in railties/lib/rails/test_unit/runner.rb — the same code that powers bin/rails test in your application.
The repo has 131 TODO/FIXME/HACK comments across 56 files
Across ~3,400 Ruby files in lib/ directories. That's about one TODO every 1,500 lines — modest for a codebase of this size and age.
You can run Rails tests against four databases in one component
Active Record is the only component that runs against multiple databases:
cd activerecord
bundle exec rake test:sqlite3
bundle exec rake test:postgresql
bundle exec rake test:mysql2
bundle exec rake test:trilogyEach adapter has a directory under activerecord/lib/active_record/connection_adapters/. Trilogy is the newest, contributed by GitHub in 2023.
Action Mailbox is the smallest gem
At 728 lines of production code, it's the smallest of the 12 components. It's mostly a mail router, a couple of Rack ingress controllers, and a small DSL. The actual SMTP work is delegated to the mail gem.
Frozen strings everywhere
Every Ruby file in the repo starts with # frozen_string_literal: true. The .rubocop.yml enforces it. As of 8.2, new applications generated by rails new even pre-load frozen-string-literals via a config/bootsnap.rb file (railties CHANGELOG, Rails 8.2.0.alpha).
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.