This project is archived and is in readonly mode.

#6388 ✓resolved

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:


{"/engine_app_engine"=>"/code/sandbox/engine_app/public", "/"=>"/code/sandbox/parent_app/public"}


#<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

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

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

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=""></a>


Referenced by