This project is archived and is in readonly mode.

#1022 ✓resolved
Martin Rehfeld

Asset caching does not work with relative_url_root

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

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.

Comments and changes to this ticket

  • Martin Rehfeld

    Martin Rehfeld September 11th, 2008 @ 11:21 AM

    • 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.

  • Martin Rehfeld

    Martin Rehfeld September 11th, 2008 @ 04:41 PM

    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.

  • Martin Rehfeld

    Martin Rehfeld September 17th, 2008 @ 09:08 PM

    • 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?

  • josh

    josh September 18th, 2008 @ 03:55 PM

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

    josh September 19th, 2008 @ 03:09 PM

    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
    
  • Martin Rehfeld

    Martin Rehfeld September 19th, 2008 @ 04:05 PM

    • 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.

  • Repository

    Repository September 22nd, 2008 @ 07:24 PM

    • State changed from “open” to “resolved”

    (from [10380a22a65d93bee6775a0ffe93071b798bf249]) Fixed AssetTag cache with with relative_url_root [#1022 state:resolved]

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

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>

Referenced by

Pages