Skip to content

Commit f369bcf

Browse files
author
Dan Kang
committed
Default config.assets.digests to true in development
1 parent dbbcc83 commit f369bcf

File tree

7 files changed

+47
-23
lines changed

7 files changed

+47
-23
lines changed

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ gem 'jquery-rails', '~> 3.1.0'
1212
gem 'turbolinks'
1313
gem 'coffee-rails', '~> 4.0.0'
1414
gem 'arel', github: 'rails/arel', branch: 'master'
15-
gem 'sprockets-rails', github: 'rails/sprockets-rails', branch: '2-1-stable'
15+
gem 'sprockets-rails', github: 'rails/sprockets-rails', branch: 'master'
1616
gem 'i18n', github: 'svenfuchs/i18n', branch: 'master'
1717

1818
# require: false so bcrypt is loaded only when has_secure_password is used.

guides/code/getting_started/config/environments/development.rb

+8
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,12 @@
2727

2828
# Debug mode disables concatenation and preprocessing of assets.
2929
config.assets.debug = true
30+
31+
# Generate digests for assets URLs.
32+
config.assets.digest = true
33+
34+
# Adds additional error checking when serving assets at runtime.
35+
# Checks for improperly declared sprockets dependencies.
36+
# Raises helpful error messages.
37+
config.assets.raise_runtime_errors = true
3038
end

guides/source/asset_pipeline.md

+18-8
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,9 @@ will result in your assets being included more than once.
198198

199199
WARNING: When using asset precompilation, you will need to ensure that your
200200
controller assets will be precompiled when loading them on a per page basis. By
201-
default .coffee and .scss files will not be precompiled on their own. This will
202-
result in false positives during development as these files will work just fine
203-
since assets are compiled on the fly in development mode. When running in
204-
production, however, you will see 500 errors since live compilation is turned
205-
off by default. See [Precompiling Assets](#precompiling-assets) for more
206-
information on how precompiling works.
201+
default .coffee and .scss files will not be precompiled on their own. See
202+
[Precompiling Assets](#precompiling-assets) for more information on how
203+
precompiling works.
207204

208205
NOTE: You must have an ExecJS supported runtime in order to use CoffeeScript.
209206
If you are using Mac OS X or Windows, you have a JavaScript runtime installed in
@@ -581,8 +578,21 @@ runtime. To disable this behavior you can set:
581578
config.assets.raise_runtime_errors = false
582579
```
583580

584-
When this option is true asset pipeline will check if all the assets loaded in your application
585-
are included in the `config.assets.precompile` list.
581+
When this option is true, the asset pipeline will check if all the assets loaded
582+
in your application are included in the `config.assets.precompile` list.
583+
If `config.assets.digests` is also true, the asset pipeline will require that
584+
all requests for assets include digests.
585+
586+
### Turning Digests Off
587+
588+
You can turn off digests by updating `config/environments/development.rb` to
589+
include:
590+
591+
```ruby
592+
config.assets.digests = false
593+
```
594+
595+
When this option is true, digests will be generated for asset URLs.
586596

587597
### Turning Debugging Off
588598

railties/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Default `config.assets.digest` to `true` in development.
2+
3+
*Dan Kang*
4+
15
* Load database configuration from the first
26
database.yml available in paths.
37

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

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ Rails.application.configure do
3030
# number of complex assets.
3131
config.assets.debug = true
3232

33+
# Generate digests for assets URLs.
34+
config.assets.digest = true
35+
3336
# Adds additional error checking when serving assets at runtime.
3437
# Checks for improperly declared sprockets dependencies.
3538
# Raises helpful error messages.

railties/test/application/assets_test.rb

+11-14
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ def assert_no_file_exists(filename)
5050
end
5151
RUBY
5252

53+
add_to_env_config "development", "config.assets.digest = false"
54+
5355
require "#{app_path}/config/environment"
5456

5557
get "/assets/demo.js"
@@ -189,7 +191,6 @@ class User < ActiveRecord::Base; raise 'should not be reached'; end
189191
end
190192

191193
test "asset pipeline should use a Sprockets::Index when config.assets.digest is true" do
192-
add_to_config "config.assets.digest = true"
193194
add_to_config "config.action_controller.perform_caching = false"
194195

195196
ENV["RAILS_ENV"] = "production"
@@ -202,8 +203,6 @@ class User < ActiveRecord::Base; raise 'should not be reached'; end
202203
app_file "app/assets/images/rails.png", "notactuallyapng"
203204
app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>"
204205
app_file "app/assets/javascripts/application.js", "alert();"
205-
# digest is default in false, we must enable it for test environment
206-
add_to_config "config.assets.digest = true"
207206

208207
precompile!
209208
manifest = Dir["#{app_path}/public/assets/manifest-*.json"].first
@@ -215,8 +214,6 @@ class User < ActiveRecord::Base; raise 'should not be reached'; end
215214

216215
test "the manifest file should be saved by default in the same assets folder" do
217216
app_file "app/assets/javascripts/application.js", "alert();"
218-
# digest is default in false, we must enable it for test environment
219-
add_to_config "config.assets.digest = true"
220217
add_to_config "config.assets.prefix = '/x'"
221218

222219
precompile!
@@ -249,7 +246,6 @@ class User < ActiveRecord::Base; raise 'should not be reached'; end
249246
test "precompile properly refers files referenced with asset_path and runs in the provided RAILS_ENV" do
250247
app_file "app/assets/images/rails.png", "notactuallyapng"
251248
app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>"
252-
# digest is default in false, we must enable it for test environment
253249
add_to_env_config "test", "config.assets.digest = true"
254250

255251
precompile!('RAILS_ENV=test')
@@ -281,12 +277,9 @@ class User < ActiveRecord::Base; raise 'should not be reached'; end
281277
test "precompile appends the md5 hash to files referenced with asset_path and run in production with digest true" do
282278
app_file "app/assets/images/rails.png", "notactuallyapng"
283279
app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>"
284-
add_to_config "config.assets.compile = true"
285-
add_to_config "config.assets.digest = true"
286280

287-
ENV["RAILS_ENV"] = nil
288-
289-
precompile!('RAILS_GROUPS=assets')
281+
ENV["RAILS_ENV"] = "production"
282+
precompile!
290283

291284
file = Dir["#{app_path}/public/assets/application-*.css"].first
292285
assert_match(/\/assets\/rails-([0-z]+)\.png/, File.read(file))
@@ -342,6 +335,8 @@ class User < ActiveRecord::Base; raise 'should not be reached'; end
342335
end
343336
RUBY
344337

338+
add_to_env_config "development", "config.assets.digest = false"
339+
345340
require "#{app_path}/config/environment"
346341

347342
class ::OmgController < ActionController::Base
@@ -366,6 +361,8 @@ def index
366361

367362
app_file "app/assets/javascripts/demo.js", "alert();"
368363

364+
add_to_env_config "development", "config.assets.digest = false"
365+
369366
require "#{app_path}/config/environment"
370367

371368
get "/assets/demo.js"
@@ -395,7 +392,6 @@ class ::PostsController < ActionController::Base ; end
395392
app_file "app/assets/javascripts/application.js", "//= require_tree ."
396393
app_file "app/assets/javascripts/xmlhr.js.erb", "<%= Post.name %>"
397394

398-
add_to_config "config.assets.digest = false"
399395
precompile!
400396
assert_equal "Post;\n", File.read(Dir["#{app_path}/public/assets/application-*.js"].first)
401397
end
@@ -415,7 +411,6 @@ class ::PostsController < ActionController::Base ; end
415411
test "digested assets are not mistakenly removed" do
416412
app_file "app/assets/application.js", "alert();"
417413
add_to_config "config.assets.compile = true"
418-
add_to_config "config.assets.digest = true"
419414

420415
precompile!
421416

@@ -438,6 +433,7 @@ class ::PostsController < ActionController::Base ; end
438433
test "asset urls should use the request's protocol by default" do
439434
app_with_assets_in_view
440435
add_to_config "config.asset_host = 'example.com'"
436+
add_to_env_config "development", "config.assets.digest = false"
441437
require "#{app_path}/config/environment"
442438
class ::PostsController < ActionController::Base; end
443439

@@ -452,6 +448,7 @@ class ::PostsController < ActionController::Base; end
452448
app_file "app/assets/javascripts/image_loader.js.erb", "var src='<%= image_path('rails.png') %>';"
453449
add_to_config "config.assets.precompile = %w{rails.png image_loader.js}"
454450
add_to_config "config.asset_host = 'example.com'"
451+
add_to_env_config "development", "config.assets.digest = false"
455452
precompile!
456453

457454
assert_match "src='//example.com/assets/rails.png'", File.read(Dir["#{app_path}/public/assets/image_loader-*.js"].first)
@@ -460,9 +457,9 @@ class ::PostsController < ActionController::Base; end
460457
test "asset paths should use RAILS_RELATIVE_URL_ROOT by default" do
461458
ENV["RAILS_RELATIVE_URL_ROOT"] = "/sub/uri"
462459
app_file "app/assets/images/rails.png", "notreallyapng"
463-
464460
app_file "app/assets/javascripts/app.js.erb", "var src='<%= image_path('rails.png') %>';"
465461
add_to_config "config.assets.precompile = %w{rails.png app.js}"
462+
add_to_env_config "development", "config.assets.digest = false"
466463
precompile!
467464

468465
assert_match "src='/sub/uri/assets/rails.png'", File.read(Dir["#{app_path}/public/assets/app-*.js"].first)

railties/test/railties/engine_test.rb

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def boot_rails
3434

3535
test "serving sprocket's assets" do
3636
@plugin.write "app/assets/javascripts/engine.js.erb", "<%= :alert %>();"
37+
add_to_env_config "development", "config.assets.digest = false"
3738

3839
boot_rails
3940
require 'rack/test'
@@ -1080,6 +1081,7 @@ def bar
10801081
RUBY
10811082

10821083
add_to_config("config.railties_order = [:all, :main_app, Blog::Engine]")
1084+
add_to_env_config "development", "config.assets.digest = false"
10831085

10841086
boot_rails
10851087

0 commit comments

Comments
 (0)