rails/rails
Configuration
This page documents where configuration lives in the codebase, not the exhaustive list of options. The exhaustive user-facing list is at guides/source/configuring.md (rendered as https://guides.rubyonrails.org/configuring.html).
Where config.* is defined
Configuration is layered:
Rails::Application::Configuration—railties/lib/rails/application/configuration.rb. The top-level container. Has direct attributes (config.eager_load,config.cache_classes,config.middleware, etc.) and one nested namespace per framework component.- Per-component config namespaces —
config.active_record,config.action_controller,config.active_job, etc. Each is anActiveSupport::OrderedOptionspopulated by the component's railtie. - Component class attributes — many config flags map onto class attributes via the railtie (e.g.,
config.action_view.field_error_procbecomesActionView::Base.field_error_proc).
Reading configuration in framework code
Inside framework code:
ActionView::Base.remove_hidden_field_autocompleteReading it through the application config:
Rails.application.config.action_view.remove_hidden_field_autocompleteBoth ultimately point at the same cattr_accessor defined on the framework's base class. The railtie wires them together at boot.
The load_defaults system
Rails::Application::Configuration#load_defaults(version) opts the app into the recommended config for a Rails version. Implementation:
railties/lib/rails/application/configuration.rb— the case statement.- Each new defaults block flips on the recommended flags for that version.
For example, the 8.1 block (excerpt-style):
case target_version.to_s
when "8.1"
action_view.remove_hidden_field_autocomplete = true
...When you upgrade an app, you bump config.load_defaults 8.1 to get the new defaults. Apps that haven't bumped continue running with the previous behavior.
The configuration-flag pattern
When adding a flag, follow the pattern documented in how-to-contribute/patterns-and-conventions:
cattr_accessor :flag_name, default: falseon the component's base class.- Read the flag at the call site.
- Wire into
load_defaultsfor new defaults. - Document in
guides/source/configuring.md.
Notable namespaces
| Namespace | File | Notes |
|---|---|---|
config |
railties/lib/rails/application/configuration.rb |
Top-level |
config.middleware |
actionpack/lib/action_dispatch/middleware/stack.rb |
Insert / delete middlewares |
config.generators |
railties/lib/rails/generators.rb |
Generator defaults |
config.active_support |
activesupport/lib/active_support/railtie.rb |
Logger, time zone, error reporter |
config.active_record |
activerecord/lib/active_record/railtie.rb |
Migration paths, schema format, query log tags, encryption |
config.action_controller |
actionpack/lib/action_controller/railtie.rb |
Forgery protection, parameter wrappers, log subscribers |
config.action_dispatch |
actionpack/lib/action_dispatch/railtie.rb |
Trusted proxies, hosts, session store |
config.action_view |
actionview/lib/action_view/railtie.rb |
Field error proc, prefix partials, automatic ETags |
config.action_mailer |
actionmailer/lib/action_mailer/railtie.rb |
Default URL options, delivery method |
config.action_mailbox |
actionmailbox/lib/action_mailbox/engine.rb |
Ingress provider, incineration interval |
config.active_job |
activejob/lib/active_job/railtie.rb |
Queue adapter, name prefix, default retries |
config.action_cable |
actioncable/lib/action_cable/engine.rb |
Mount path, allowed origins |
config.active_storage |
activestorage/lib/active_storage/engine.rb |
Service, variant processor, allowed file types |
config.action_text |
actiontext/lib/action_text/engine.rb |
Sanitization rules, attachment tags |
Environment-specific config
config/environments/{development,test,production}.rb is loaded between before_configuration and before_initialize callbacks (see features/initialization-and-railties). It's plain Ruby evaluated against Rails.application.config, so it can override anything set elsewhere.
Encrypted credentials
config.credentials is backed by an encrypted YAML file (config/credentials.yml.enc) decrypted with a master key. Implementation:
railties/lib/rails/secrets.rbactivesupport/lib/active_support/encrypted_configuration.rbactivesupport/lib/active_support/encrypted_file.rb
Per-environment credentials live under config/credentials/<env>.yml.enc with their own keys.
Inspecting in an app
bin/rails about # Versions, env, database
bin/rails initializers # Resolved initializer order
bin/rails middleware # Final middleware stack
bin/rails routes # All defined routes
bin/rails db:schema_cache:dumpThese commands are implemented under railties/lib/rails/commands/.
Related pages
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.