Skip to content

Commit 4755259

Browse files
authored
Merge pull request rails#45385 from skipkayhil/refine-configuring-docs-2
Add docs for all Application::Configuration attr [ci skip]
2 parents 2d2fd94 + db0f2a4 commit 4755259

File tree

2 files changed

+149
-35
lines changed

2 files changed

+149
-35
lines changed

guides/source/configuring.md

Lines changed: 141 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,17 @@ Below are the default values associated with each target version. In cases of co
147147

148148
The following configuration methods are to be called on a `Rails::Railtie` object, such as a subclass of `Rails::Engine` or `Rails::Application`.
149149

150+
#### `config.add_autoload_paths_to_load_path`
151+
152+
Says whether autoload paths have to be added to `$LOAD_PATH`. It is recommended to be set to `false` in `:zeitwerk` mode early, in `config/application.rb`. Zeitwerk uses absolute paths internally, and applications running in `:zeitwerk` mode do not need `require_dependency`, so models, controllers, jobs, etc. do not need to be in `$LOAD_PATH`. Setting this to `false` saves Ruby from checking these directories when resolving `require` calls with relative paths, and saves Bootsnap work and RAM, since it does not need to build an index for them.
153+
154+
The default value depends on the `config.load_defaults` target version:
155+
156+
| Starting with version | The default value is |
157+
| --------------------- | -------------------- |
158+
| (original) | `true` |
159+
| 7.1 | `false` |
160+
150161
#### `config.after_initialize`
151162

152163
Takes a block which will be run _after_ Rails has finished initializing the application. That includes the initialization of the framework itself, engines, and all the application's initializers in `config/initializers`. Note that this block _will_ be run for rake tasks. Useful for configuring values set up by other initializers:
@@ -157,10 +168,20 @@ config.after_initialize do
157168
end
158169
```
159170

171+
#### `config.allow_concurrency`
172+
173+
Controls whether requests should be handled concurrently. This should only
174+
be set to `false` if application code is not thread safe. Defaults to `true`.
175+
160176
#### `config.asset_host`
161177

162178
Sets the host for the assets. Useful when CDNs are used for hosting assets, or when you want to work around the concurrency constraints built-in in browsers using different domain aliases. Shorter version of `config.action_controller.asset_host`.
163179

180+
#### `config.autoflush_log`
181+
182+
Enables writing log file output immediately instead of buffering. Defaults to
183+
`true`.
184+
164185
#### `config.autoload_once_paths`
165186

166187
Accepts an array of paths from which Rails will autoload constants that won't be wiped per request. Relevant if reloading is enabled, which it is by default in the `development` environment. Otherwise, all autoloading happens only once. All elements of this array must also be in `autoload_paths`. Default is an empty array.
@@ -169,32 +190,15 @@ Accepts an array of paths from which Rails will autoload constants that won't be
169190

170191
Accepts an array of paths from which Rails will autoload constants. Default is an empty array. Since [Rails 6](upgrading_ruby_on_rails.html#autoloading), it is not recommended to adjust this. See [Autoloading and Reloading Constants](autoloading_and_reloading_constants.html#autoload-paths).
171192

172-
#### `config.add_autoload_paths_to_load_path`
173-
174-
Says whether autoload paths have to be added to `$LOAD_PATH`. It is recommended to be set to `false` in `:zeitwerk` mode early, in `config/application.rb`. Zeitwerk uses absolute paths internally, and applications running in `:zeitwerk` mode do not need `require_dependency`, so models, controllers, jobs, etc. do not need to be in `$LOAD_PATH`. Setting this to `false` saves Ruby from checking these directories when resolving `require` calls with relative paths, and saves Bootsnap work and RAM, since it does not need to build an index for them.
175-
176-
The default value depends on the `config.load_defaults` target version:
177-
178-
| Starting with version | The default value is |
179-
| --------------------- | -------------------- |
180-
| (original) | `true` |
181-
| 7.1 | `false` |
182-
183-
#### `config.enable_reloading`
184-
185-
If `config.enable_reloading` is true, application classes and modules are reloaded in between web requests if they change. Defaults to `true` in the `development` environment, and `false` in the `production` environment.
193+
#### `config.beginning_of_week`
186194

187-
The predicate `config.reloading_enabled?` is also defined.
195+
Sets the default beginning of week for the
196+
application. Accepts a valid day of week as a symbol (e.g. `:monday`).
188197

189198
#### `config.cache_classes`
190199

191200
Old setting equivalent to `!config.enable_reloading`. Supported for backwards compatibility.
192201

193-
#### `config.beginning_of_week`
194-
195-
Sets the default beginning of week for the
196-
application. Accepts a valid day of week as a symbol (e.g. `:monday`).
197-
198202
#### `config.cache_store`
199203

200204
Configures which cache store to use for Rails caching. Options include one of the symbols `:memory_store`, `:file_store`, `:mem_cache_store`, `:null_store`, `:redis_cache_store`, or an object that implements the cache API. Defaults to `:file_store`. See [Cache Stores](caching_with_rails.html#cache-stores) for per-store configuration options.
@@ -220,6 +224,31 @@ console do
220224
end
221225
```
222226

227+
#### `config.content_security_policy_nonce_directives`
228+
229+
See [Adding a Nonce](security.html#adding-a-nonce) in the Security Guide
230+
231+
#### `config.content_security_policy_nonce_generator`
232+
233+
See [Adding a Nonce](security.html#adding-a-nonce) in the Security Guide
234+
235+
#### `config.content_security_policy_report_only`
236+
237+
See [Reporting Violations](security.html#reporting-violations) in the Security
238+
Guide
239+
240+
#### `config.credentials.content_path`
241+
242+
Configures lookup path for encrypted credentials.
243+
244+
#### `config.credentials.key_path`
245+
246+
Configures lookup path for encryption key.
247+
248+
#### `config.debug_exception_response_format`
249+
250+
Sets the format used in responses when errors occur in the development environment. Defaults to `:api` for API only apps and `:default` for normal apps.
251+
223252
#### `config.disable_sandbox`
224253

225254
Controls whether or not someone can start a console in sandbox mode. This is helpful to avoid a long running session of sandbox console, that could lead a database server to run out of memory. Defaults to `false`.
@@ -236,6 +265,12 @@ Registers namespaces that are eager loaded when `config.eager_load` is set to `t
236265

237266
Accepts an array of paths from which Rails will eager load on boot if `config.eager_load` is true. Defaults to every folder in the `app` directory of the application.
238267

268+
#### `config.enable_reloading`
269+
270+
If `config.enable_reloading` is true, application classes and modules are reloaded in between web requests if they change. Defaults to `true` in the `development` environment, and `false` in the `production` environment.
271+
272+
The predicate `config.reloading_enabled?` is also defined.
273+
239274
#### `config.encoding`
240275

241276
Sets up the application-wide encoding. Defaults to UTF-8.
@@ -244,10 +279,6 @@ Sets up the application-wide encoding. Defaults to UTF-8.
244279

245280
Sets the exceptions application invoked by the `ShowException` middleware when an exception happens. Defaults to `ActionDispatch::PublicExceptions.new(Rails.public_path)`.
246281

247-
#### `config.debug_exception_response_format`
248-
249-
Sets the format used in responses when errors occur in the development environment. Defaults to `:api` for API only apps and `:default` for normal apps.
250-
251282
#### `config.file_watcher`
252283

253284
Is the class used to detect file updates in the file system when `config.reload_classes_only_on_change` is `true`. Rails ships with `ActiveSupport::FileUpdateChecker`, the default, and `ActiveSupport::EventedFileUpdateChecker` (this one depends on the [listen](https://github.com/guard/listen) gem). Custom classes must conform to the `ActiveSupport::FileUpdateChecker` API.
@@ -268,10 +299,37 @@ Rails.application.config.filter_parameters += [
268299

269300
Parameters filter works by partial matching regular expression.
270301

302+
#### `config.filter_redirect`
303+
304+
Used for filtering out redirect urls from application logs.
305+
306+
```ruby
307+
Rails.application.config.filter_redirect += ['s3.amazonaws.com', /private-match/]
308+
```
309+
310+
The redirect filter works by testing that urls include strings or match regular
311+
expressions.
312+
271313
#### `config.force_ssl`
272314

273315
Forces all requests to be served over HTTPS, and sets "https://" as the default protocol when generating URLs. Enforcement of HTTPS is handled by the `ActionDispatch::SSL` middleware, which can be configured via `config.ssl_options`.
274316

317+
#### `config.helpers_paths`
318+
319+
Defines an array of additional paths to load view helpers.
320+
321+
#### `config.host_authorization`
322+
323+
Accepts a hash of options to configure the [HostAuthorization
324+
middleware](#actiondispatch-hostauthorization)
325+
326+
#### `config.hosts`
327+
328+
An array of strings, regular expressions, or `IPAddr` used to validate the
329+
`Host` header. Used by the [HostAuthorization
330+
middleware](#actiondispatch-hostauthorization) to help prevent DNS rebinding
331+
attacks.
332+
275333
#### `config.javascript_path`
276334

277335
Sets the path where your app's JavaScript lives relative to the `app` directory. The default is `javascript`, used by [webpacker](https://github.com/rails/webpacker). An app's configured `javascript_path` will be excluded from `autoload_paths`.
@@ -314,21 +372,44 @@ config.logger = ActiveSupport::TaggedLogging.new(mylogger)
314372

315373
Allows you to configure the application's middleware. This is covered in depth in the [Configuring Middleware](#configuring-middleware) section below.
316374

375+
#### `config.public_file_server.enabled`
376+
377+
Configures Rails to serve static files from the public directory. This option defaults to `true`, but in the production environment it is set to `false` because the server software (e.g. NGINX or Apache) used to run the application should serve static files instead. If you are running or testing your app in production using WEBrick (it is not recommended to use WEBrick in production) set the option to `true`. Otherwise, you won't be able to use page caching and request for files that exist under the public directory.
378+
379+
#### `config.railties_order`
380+
381+
Allows manually specifying the order that Railties/Engines are loaded. The
382+
default value is `[:all]`.
383+
384+
```ruby
385+
config.railties_order = [Blog::Engine, :main_app, :all]
386+
```
387+
317388
#### `config.rake_eager_load`
318389

319390
When `true`, eager load the application when running Rake tasks. Defaults to `false`.
320391

321-
#### `config.reload_classes_only_on_change`
392+
#### `config.read_encrypted_secrets`
322393

323-
Enables or disables reloading of classes only when tracked files change. By default tracks everything on autoload paths and is set to `true`. If `config.enable_reloading` is `false`, this option is ignored.
394+
*DEPRECATED*: You should be using
395+
[credentials](https://guides.rubyonrails.org/security.html#custom-credentials)
396+
instead of encrypted secrets.
324397

325-
#### `config.credentials.content_path`
398+
When `true`, will try to read encrypted secrets from `config/secrets.yml.enc`
326399

327-
Configures lookup path for encrypted credentials.
400+
#### `config.relative_url_root`
328401

329-
#### `config.credentials.key_path`
402+
Can be used to tell Rails that you are [deploying to a subdirectory](
403+
configuring.html#deploy-to-a-subdirectory-relative-url-root). The default
404+
is `ENV['RAILS_RELATIVE_URL_ROOT']`.
330405

331-
Configures lookup path for encryption key.
406+
#### `config.reload_classes_only_on_change`
407+
408+
Enables or disables reloading of classes only when tracked files change. By default tracks everything on autoload paths and is set to `true`. If `config.enable_reloading` is `false`, this option is ignored.
409+
410+
#### `config.require_master_key`
411+
412+
Causes the app to not boot if a master key hasn't been made available through `ENV["RAILS_MASTER_KEY"]` or the `config/master.key` file.
332413

333414
#### `config.secret_key_base`
334415

@@ -338,13 +419,20 @@ in `config/credentials.yml.enc`. See the [`secret_key_base` API documentation](
338419
https://api.rubyonrails.org/classes/Rails/Application.html#method-i-secret_key_base)
339420
for more information and alternative configuration methods.
340421

341-
#### `config.require_master_key`
422+
#### `config.server_timing`
342423

343-
Causes the app to not boot if a master key hasn't been made available through `ENV["RAILS_MASTER_KEY"]` or the `config/master.key` file.
424+
When `true`, adds the [ServerTiming middleware](#actiondispatch-servertiming)
425+
to the middleware stack
344426

345-
#### `config.public_file_server.enabled`
427+
#### `config.session_options`
346428

347-
Configures Rails to serve static files from the public directory. This option defaults to `true`, but in the production environment it is set to `false` because the server software (e.g. NGINX or Apache) used to run the application should serve static files instead. If you are running or testing your app in production using WEBrick (it is not recommended to use WEBrick in production) set the option to `true`. Otherwise, you won't be able to use page caching and request for files that exist under the public directory.
429+
Additional options passed to `config.session_store`. You should use
430+
`config.session_store` to set this instead of modifying it yourself.
431+
432+
```ruby
433+
config.session_store :cookie_store, key: "_your_app_session"
434+
config.session_options # => {key: "_your_app_session"}
435+
```
348436

349437
#### `config.session_store`
350438

@@ -380,6 +468,17 @@ The default value depends on the `config.load_defaults` target version:
380468

381469
Sets the default time zone for the application and enables time zone awareness for Active Record.
382470

471+
#### `config.x`
472+
473+
Used to easily add nested custom configuration to the application config object
474+
475+
```ruby
476+
config.x.payment_processing.schedule = :daily
477+
Rails.configuration.x.payment_processing.schedule # => :daily
478+
```
479+
480+
See [Custom Configuration](#custom-configuration)
481+
383482
### Configuring Assets
384483

385484
#### `config.assets.css_compressor`
@@ -541,6 +640,11 @@ Rails.application.config.host_authorization = {
541640
}
542641
```
543642

643+
#### `ActionDispatch::ServerTiming`
644+
645+
Adds metrics to the `Server-Timing` header to be viewed in the dev tools of a
646+
browser.
647+
544648
#### `ActionDispatch::SSL`
545649

546650
Forces every request to be served using HTTPS. Enabled if `config.force_ssl` is set to `true`. Options passed to this can be configured by setting `config.ssl_options`.
@@ -1168,7 +1272,9 @@ The default value depends on the `config.load_defaults` target version:
11681272
11691273
#### `config.action_controller.relative_url_root`
11701274
1171-
Can be used to tell Rails that you are [deploying to a subdirectory](configuring.html#deploy-to-a-subdirectory-relative-url-root). The default is `ENV['RAILS_RELATIVE_URL_ROOT']`.
1275+
Can be used to tell Rails that you are [deploying to a subdirectory](
1276+
configuring.html#deploy-to-a-subdirectory-relative-url-root). The default is
1277+
[`config.relative_url_root`](#config-relative-url-root).
11721278
11731279
#### `config.action_controller.permit_all_parameters`
11741280

guides/source/security.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,14 @@ This generation method is compatible with ETags, however its security depends on
12531253
the session id being sufficiently random and not being exposed in insecure
12541254
cookies.
12551255

1256+
By default, nonces will be applied to `script-src` and `style-src` if a nonce
1257+
generator is defined. `config.content_security_policy_nonce_directives` can be
1258+
used to change which directives will use nonces:
1259+
1260+
```ruby
1261+
Rails.application.config.content_security_policy_nonce_directives = %w(script-src)
1262+
```
1263+
12561264
Once nonce generation is configured in an initializer, automatic nonce values
12571265
can be added to script tags by passing `nonce: true` as part of `html_options`:
12581266

0 commit comments

Comments
 (0)