Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Asset caching does not work with relative_url_root

#1022

A relative URL root, i.e. http://www.example.com/collabora..., with ActionController::AbstractRequest.relative_url_root set accordingly will make asset caching fail.

Both


stylesheet_link_tag(:all, :cache => true)

and


javascript_include_tag(:all, :cache => true)

will raise

Errno::ENOENT: No such file or directory when trying to read the respective assets from the local filesystem. By mistake the relative_url_root gets included into the local filesystem path (AssetTagHelper#compute_public_path, l.498)

The attached patch to asset_tag_helper_test.rb demonstrates the problem.

Reported by Martin Rehfeld · September 11th, 2008 @ 10:59 AM

State: resolved
Milestone: none
Assigned to: josh josh
Importance: none

Activity

  1. Martin Rehfeld
    Martin Rehfeld
    • Tag changed from actionpack, bug, helper to actionpack, bug, helper, patch

    A possible fix could be to add variants of compute_javascript_paths and compute_stylesheet_paths to explictly handle paths for the local filesystem which in turn call compute_public_path with a new optional boolean parameter that will allow suppressing the insertion of relative_url_root into the source path.

    My shot at it is attached -- it makes the tests pass again and does not seem to brake anything else.

    September 11th, 2008 @ 11:21 AM

  2. Martin Rehfeld
    Martin Rehfeld

    It's probably a good idea to update the cache key in compute_public_path to include new optional parameter filesystem_path as well. Find an additional patch attached.

    September 11th, 2008 @ 04:41 PM

  3. Martin Rehfeld
    Martin Rehfeld
    • Assigned user set to josh
    • Tag changed from actionpack, bug, helper, patch to 2.1, actionpack, bug, helper, patch

    Any opinion on extending the cache key or the suggested solution in general?

    September 17th, 2008 @ 09:08 PM

  4. josh
    josh
    • Milestone cleared.
    • State changed from new to open
    • Tag changed from 2.1, actionpack, bug, helper, patch to actionpack, bug, patch

    September 18th, 2008 @ 03:55 PM

  5. josh
    josh

    Would this work as well?

    
        source
      else
        source = "/#{dir}/#{source}" unless source[0] == ?/
    -   if has_request
    +   if has_request && include_host
        unless source =~ %r{^#{ActionController::Base.relative_url_root}/}
          source = "#{ActionController::Base.relative_url_root}#{source}"
        end
    

    September 19th, 2008 @ 03:09 PM

  6. Martin Rehfeld
    Martin Rehfeld
    • Tag changed from actionpack, bug, patch to actionpack, bug, patch, tiny

    Good catch! This seems to be the shortest possible fix one could imagine. I can confirm that both the newly introduced tests are passing and the fix also works with a real-life app. Updated patches are attached (rebased to current master while we're at it).

    +1 from my side.

    September 19th, 2008 @ 04:05 PM

  7. Repository
    Repository
    • State changed from open to resolved

    (from [10380a22a65d93bee6775a0ffe93071b798bf249]) Fixed AssetTag cache with with relative_url_root [#1022 Asset caching does not work with relative_url_root state:resolved]

    Signed-off-by: Joshua Peek josh@joshpeek.com http://github.com/rails/rails/co...

    September 22nd, 2008 @ 07:24 PM