This project is archived and is in readonly mode.
Engine's static assets taking priority over applications
Reported by rubymaverick | February 8th, 2011 @ 05:09 AM | in 3.1
When serve_static_assets = true, an engine's static assets are taking priority over an application's. This is happening on Edge Rails. I created a barebones rails app with a barebones engine and config.static_asset_paths--when loading the 'ActionDispatch::Static' middleware--is:
1.9.2:
{"/engine_app_engine"=>"/code/sandbox/engine_app/public", "/"=>"/code/sandbox/parent_app/public"}
1.8.7:
#<OrderedHash {"/"=>"/code/sandbox/parent_app/public", "/engine_app_engine"=>"/code/sandbox/engine_app/public"}>
But both result in the same FileHandlers being created in
ActionDispatch::Static:
[#<ActionDispatch::FileHandler:0x1021a6960 @file_server=#<Rack::File:0x1021a66e0 @root="/code/sandbox/engine_app/public">, @at="/engine_app_engine", @compiled_root=/^\/code\/sandbox\/engine_app\/public/, @root="/code/sandbox/engine_app/public", @compiled_at=/^\/engine_app_engine/>, #<ActionDispatch::FileHandler:0x1021a66b8 @file_server=#<Rack::File:0x1021a6500 @root="/code/sandbox/parent_app/public">, @at="", @compiled_root=/^\/code\/sandbox\/parent_app\/public/, @root="/code/sandbox/parent_app/public", @compiled_at=nil>]
The engine is:
module EngineApp
class Engine < Rails::Engine
end
end
So when ActionDispatch::Static is getting called, it first looks in the engine's public directory, and then if not found, the applications public directory. It seems like this has something to do with initialization order. Here is where those static_asset_paths are getting set:
# in railties/lib/rails/engine.rb
initializer :append_asset_paths do
config.asset_path ||= default_asset_path
public_path = paths["public"].first
if config.compiled_asset_path && File.exist?(public_path)
config.static_asset_paths[config.compiled_asset_path] = public_path
end
end
So since static_asset_paths is using an OrderedHash, this initializer must be getting called on the engine, then the application (since the application is just also an engine).
Tested on 1.9.2-p136, 1.8.7-p302
Comments and changes to this ticket
-
rubymaverick February 8th, 2011 @ 03:31 PM
I created repo's on GitHub for the Parent App (https://github.com/rubymaverick/Parent-App) and the Engine (https://github.com/rubymaverick/Engine-App) so anyone can replicate this. Just pull down both repos into the same directory, use bundler to resolve the parent apps dependencies, fire up the server, and go to http://localhost:3000/engine-app.
The file parent_app/public/engine_app_engine/stylesheets/style.css does not get served, instead engine_app/public/stylesheets/style.css does.
-
rubymaverick February 8th, 2011 @ 05:11 PM
Another failing test. Proves that engines initializers are loaded before the applications, which I think is the cause of the problem?
-
José Valim February 8th, 2011 @ 09:57 PM
- State changed from new to open
- Milestone set to 3.1
- Assigned user set to Piotr Sarnacki
- Importance changed from to High
Piotr, could you please take a look at this?
-
Piotr Sarnacki February 9th, 2011 @ 11:05 AM
@rubymaverick: the loading of initializers is ok, they should load before application's ones, I just haven't noticed that with such behavior assets from engine will have higher priority.
-
Repository February 9th, 2011 @ 11:20 AM
- State changed from open to resolved
(from [e6369bc9e97d0f1e5583725cd9f684bbe4fca3e1]) Application's assets should have higher priority than engine's ones [#6388 state:resolved] https://github.com/rails/rails/commit/e6369bc9e97d0f1e5583725cd9f68...
-
Piotr Sarnacki February 9th, 2011 @ 11:20 AM
- no changes were found...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 6388 Engine's static assets taking priority over applications (from [e6369bc9e97d0f1e5583725cd9f684bbe4fca3e1]) Applica...