mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
fixed asset_paths when called from sprockets for relative_url_root
This commit is contained in:
@@ -44,7 +44,12 @@ module ActionView
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def rewrite_relative_url_root(source, relative_url_root)
|
||||
relative_url_root && !source.starts_with?("#{relative_url_root}/") ? "#{relative_url_root}#{source}" : source
|
||||
end
|
||||
|
||||
def rewrite_host_and_protocol(source, has_request)
|
||||
source = rewrite_relative_url_root(source, controller.config.relative_url_root) if has_request
|
||||
host = compute_asset_host(source)
|
||||
if has_request && host && !is_uri?(host)
|
||||
host = "#{controller.request.protocol}#{host}"
|
||||
@@ -75,4 +80,4 @@ module ActionView
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -85,17 +85,8 @@ module ActionView
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def rewrite_relative_url_root(source, relative_url_root)
|
||||
relative_url_root && !source.starts_with?("#{relative_url_root}/") ? "#{relative_url_root}#{source}" : source
|
||||
end
|
||||
|
||||
def rewrite_host_and_protocol(source, has_request)
|
||||
source = rewrite_relative_url_root(source, controller.config.relative_url_root) if has_request
|
||||
super(source, has_request)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -58,6 +58,12 @@ class SprocketsHelperTest < ActionView::TestCase
|
||||
asset_path("http://www.example.com/video/play.mp4")
|
||||
end
|
||||
|
||||
test "asset path with relavtive url root" do
|
||||
@controller.config.relative_url_root = "/collaboration/hieraki"
|
||||
assert_equal "/collaboration/hieraki/images/logo.gif",
|
||||
asset_path("/images/logo.gif")
|
||||
end
|
||||
|
||||
test "javascript path" do
|
||||
assert_equal "/assets/application-d41d8cd98f00b204e9800998ecf8427e.js",
|
||||
asset_path(:application, "js")
|
||||
|
||||
Reference in New Issue
Block a user