Skip to content
This repository was archived by the owner on Mar 23, 2024. It is now read-only.

Commit c1a5729

Browse files
committed
Fix for overriding assets with combined versions in Rails 4.0 - fixes #137
1 parent f233010 commit c1a5729

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

lib/requirejs/rails/engine.rb

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,26 @@ class Engine < ::Rails::Engine
3535
end
3636
end
3737

38-
initializer "requirejs.manifest", :after => "sprockets.environment" do |app|
39-
config = app.config
40-
if config.requirejs.manifest_path.exist? && config.assets.digests
41-
rjs_digests = YAML.load(ERB.new(File.new(config.requirejs.manifest_path).read).result)
42-
config.assets.digests.merge!(rjs_digests)
38+
if ::Rails::VERSION::STRING >= "4.0.0"
39+
config.after_initialize do |app|
40+
config = app.config
41+
rails_manifest_path = File.join(app.root, 'public', config.assets.prefix)
42+
rails_manifest = Sprockets::Manifest.new(app.assets, rails_manifest_path)
43+
if config.requirejs.manifest_path.exist? && rails_manifest
44+
rjs_digests = YAML.load(ERB.new(File.new(config.requirejs.manifest_path).read).result)
45+
rails_manifest.assets.merge!(rjs_digests)
46+
ActionView::Base.instance_eval do
47+
self.assets_manifest = rails_manifest
48+
end
49+
end
50+
end
51+
else
52+
initializer "requirejs.manifest", :after => "sprockets.environment" do |app|
53+
config = app.config
54+
if config.requirejs.manifest_path.exist? && config.assets.digests
55+
rjs_digests = YAML.load(ERB.new(File.new(config.requirejs.manifest_path).read).result)
56+
config.assets.digests.merge!(rjs_digests)
57+
end
4358
end
4459
end
4560

0 commit comments

Comments
 (0)