Permalink
Browse files

`asset_path` respects SCRIPT_NAME.

Closes #2992
  • Loading branch information...
1 parent a8aee4d commit 83613ca60b1d536003a58839cd878a0fd8673be3 @senny committed Mar 10, 2013
View
@@ -1,5 +1,7 @@
## Rails 4.0.0 (unreleased) ##
+* `asset_path` respects SCRIPT_NAME. Fixes #2992. *Yves Senn*
+
* Fix incorrectly appended square brackets to a multiple select box
if an explicit name has been given and it already ends with "[]"
@@ -133,6 +133,8 @@ def asset_path(source, options = {})
end
relative_url_root = defined?(config.relative_url_root) && config.relative_url_root
+ request = self.request if respond_to?(:request)
+ relative_url_root ||= request.script_name if request
if relative_url_root
source = "#{relative_url_root}#{source}" unless source.starts_with?("#{relative_url_root}/")
end
@@ -733,6 +733,16 @@ def request
assert_equal "http://www.example.com/foo", @module.asset_url("foo")
end
+ def test_asset_url_with_script_name
+ @module.instance_eval do
+ def request
+ Struct.new(:base_url, :script_name).new("http://www.example.com", "/app")
+ end
+ end
+
+ assert_equal "http://www.example.com/app/foo", @module.asset_url("foo")
+ end
+
def test_asset_url_with_config_asset_host
@module.instance_eval do
def config

0 comments on commit 83613ca

Please sign in to comment.