Skip to content

Commit

Permalink
asset_path respects SCRIPT_NAME.
Browse files Browse the repository at this point in the history
Closes rails#2992
  • Loading branch information
senny committed Mar 10, 2013
1 parent a8aee4d commit 83613ca
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions actionpack/CHANGELOG.md
@@ -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 "[]"

Expand Down
2 changes: 2 additions & 0 deletions actionpack/lib/action_view/helpers/asset_url_helper.rb
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions actionpack/test/template/asset_tag_helper_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit 83613ca

Please sign in to comment.