@@ -21,14 +21,20 @@ class Engine < ::Rails::Engine
2121 config . assets . precompile += config . requirejs . precompile
2222
2323 # Check for the `requirejs:precompile:all` top-level Rake task and run the following initialization code.
24- Rake . application . top_level_tasks . each do |task_name |
25- case task_name
26- when "requirejs:precompile:all"
27- # Enable class reloading so that Sprockets doesn't freeze the assets environment. This allows settings
28- # for JS compression to be changes on a per-file basis.
29- config . cache_classes = false
24+ if defined? ( Rake . application ) && Rake . application . top_level_tasks == [ "requirejs:precompile:all" ]
25+ # Prevent Sprockets from freezing the assets environment, which allows JS compression to be toggled on a per-
26+ # file basis. This trick *will* fail if any of the lines linked to below change.
27+
28+ if ::Rails ::VERSION ::MAJOR >= 4
29+ # For Rails 4 (see
30+ # `https://github.com/rails/sprockets-rails/blob/v2.1.2/lib/sprockets/railtie.rb#L119-121`).
31+ config . cache_classes = false
32+ else
33+ # For Rails 3 (see
34+ # `https://github.com/rails/rails/blob/v3.2.19/actionpack/lib/sprockets/bootstrap.rb#L32-34`).
35+ config . assets . digest = false
3036 end
31- end if defined? ( Rake . application )
37+ end
3238
3339 manifest_directory = config . assets . manifest || File . join ( ::Rails . public_path , config . assets . prefix )
3440 manifest_path = File . join ( manifest_directory , "rjs_manifest.yml" )
@@ -44,7 +50,7 @@ class Engine < ::Rails::Engine
4450 end
4551 end
4652
47- if ::Rails ::VERSION ::STRING >= "4.0.0"
53+ if ::Rails ::VERSION ::MAJOR >= 4
4854 config . after_initialize do |app |
4955 config = app . config
5056 rails_manifest_path = File . join ( app . root , 'public' , config . assets . prefix )
0 commit comments