diff options
author | Guillermo Iguaran <guilleiguaran@gmail.com> | 2011-09-11 01:38:55 -0500 |
---|---|---|
committer | Guillermo Iguaran <guilleiguaran@gmail.com> | 2011-09-13 01:02:44 -0500 |
commit | 9279d1102c7d96810813cad0d0a666db0a549b1f (patch) | |
tree | 6fffb2f33c98219fad857b242fe13ffb0333ef98 /actionpack/lib | |
parent | a9509284cad9047693f8e5d74248ad307ab5b23d (diff) | |
download | rails-9279d1102c7d96810813cad0d0a666db0a549b1f.tar.gz rails-9279d1102c7d96810813cad0d0a666db0a549b1f.tar.bz2 rails-9279d1102c7d96810813cad0d0a666db0a549b1f.zip |
Set relative url root in assets when controller isn't available for Sprockets. Fix #2435
See https://github.com/rails/sass-rails/issues/42 for details
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/sprockets/helpers/rails_helper.rb | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/actionpack/lib/sprockets/helpers/rails_helper.rb b/actionpack/lib/sprockets/helpers/rails_helper.rb index 3987e6e17f..7d9296fa90 100644 --- a/actionpack/lib/sprockets/helpers/rails_helper.rb +++ b/actionpack/lib/sprockets/helpers/rails_helper.rb @@ -17,6 +17,7 @@ module Sprockets paths.asset_digests = asset_digests paths.compile_assets = compile_assets? paths.digest_assets = digest_assets? + paths.relative_url_root = config.action_controller.relative_url_root paths end end @@ -96,12 +97,17 @@ module Sprockets end class AssetPaths < ::ActionView::AssetPaths #:nodoc: - attr_accessor :asset_environment, :asset_prefix, :asset_digests, :compile_assets, :digest_assets + attr_accessor :asset_environment, :asset_prefix, :asset_digests, :compile_assets, + :digest_assets, :relative_url_root class AssetNotPrecompiledError < StandardError; end - def compute_public_path(source, dir, ext=nil, include_host=true, protocol=nil) - super(source, asset_prefix, ext, include_host, protocol) + def compute_public_path(source, dir, ext = nil, include_host = true, protocol = nil) + public_path = super(source, asset_prefix, ext, include_host, protocol) + if !is_uri?(public_path) && relative_url_root + public_path = rewrite_relative_url_root(public_path, relative_url_root) + end + public_path end # Return the filesystem path for the source @@ -149,6 +155,10 @@ module Sprockets source end end + + def relative_url_root + has_request? ? super : @relative_url_root + end end end end |