Skip to content

Commit 2ff2f1b

Browse files
committed
Flag config.assets.raise_runtime_errors in dev
By default `config.assets.raise_runtime_errors` should be set to `true` in development for new apps. Source: rails/sprockets-rails#100
1 parent badcd7b commit 2ff2f1b

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

guides/source/asset_pipeline.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,33 @@ would generate this HTML:
577577

578578
The `body` param is required by Sprockets.
579579

580+
### Runtime Error Checking
581+
582+
By default the asset pipeline will check for potential errors in development mode during
583+
runtime. To disable this behavior you can set:
584+
585+
```ruby
586+
config.assets.raise_runtime_errors = false
587+
```
588+
589+
When `raise_runtime_errors` is set to `false` sprockets will not check that dependencies of assets are declared properly. Here is a scenario where you must tell the asset pipeline about a dependency:
590+
591+
If you have `application.css.erb` that references `logo.png` like this:
592+
593+
```css
594+
#logo { background: url(<%= asset_data_uri 'logo.png' %>) }
595+
```
596+
597+
Then you must declare that `logo.png` is a dependency of `application.css.erb`, so when the image gets re-compiled, the css file does as well. You can do this using the `//= depend_on_asset` declaration:
598+
599+
```css
600+
//= depend_on_asset "logo.png"
601+
#logo { background: url(<%= asset_data_uri 'logo.png' %>) }
602+
```
603+
604+
Without this declaration you may experience strange behavior when pushing to production that is difficult to debug. When you have `raise_runtime_errors` set to `true`, dependencies will be checked at runtime so you can ensure that all dependencies are met.
605+
606+
580607
### Turning Debugging Off
581608

582609
You can turn off debug mode by updating `config/environments/development.rb` to

railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,10 @@ Rails.application.configure do
2929
# This option may cause significant delays in view rendering with a large
3030
# number of complex assets.
3131
config.assets.debug = true
32+
33+
# Adds additional error checking when serving assets at runtime.
34+
# Checks for improperly declared sprockets dependencies.
35+
# Raises helpful error messages.
36+
config.assets.raise_runtime_errors = true
3237
<%- end -%>
3338
end

0 commit comments

Comments
 (0)