aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/lib/action_view/helpers/asset_url_helper.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-05-16 13:31:06 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-05-16 13:31:20 -0300
commit3acf28773b5eebb09f720b7e343b9f3a1911d2e0 (patch)
tree967c722dc573cfed3e627cf9930ee50d74b54ece /actionview/lib/action_view/helpers/asset_url_helper.rb
parent8c48cd220648dc05c17def63d653fa98c3fab4de (diff)
parentdb9a5c5a1f8e2a1590f0ac9436587d58a67a629e (diff)
downloadrails-3acf28773b5eebb09f720b7e343b9f3a1911d2e0.tar.gz
rails-3acf28773b5eebb09f720b7e343b9f3a1911d2e0.tar.bz2
rails-3acf28773b5eebb09f720b7e343b9f3a1911d2e0.zip
Merge pull request #15021 from hubertlepicki/allow_custom_host_in_asset_url
Allow custom asset host to be passed in asset_url
Diffstat (limited to 'actionview/lib/action_view/helpers/asset_url_helper.rb')
-rw-r--r--actionview/lib/action_view/helpers/asset_url_helper.rb12
1 files changed, 10 insertions, 2 deletions
diff --git a/actionview/lib/action_view/helpers/asset_url_helper.rb b/actionview/lib/action_view/helpers/asset_url_helper.rb
index 41997a85b3..ae684af87b 100644
--- a/actionview/lib/action_view/helpers/asset_url_helper.rb
+++ b/actionview/lib/action_view/helpers/asset_url_helper.rb
@@ -147,7 +147,14 @@ module ActionView
# Computes the full URL to an asset in the public directory. This
# will use +asset_path+ internally, so most of their behaviors
- # will be the same.
+ # will be the same. If :host options is set, it overwrites global
+ # +config.action_controller.asset_host+ setting.
+ #
+ # All other options provided are forwarded to +asset_path+ call.
+ #
+ # asset_url "application.js" # => http://example.com/application.js
+ # asset_url "application.js", host: "http://cdn.example.com" # => http://cdn.example.com/javascripts/application.js
+ #
def asset_url(source, options = {})
path_to_asset(source, options.merge(:protocol => :request))
end
@@ -191,7 +198,8 @@ module ActionView
# (proc or otherwise).
def compute_asset_host(source = "", options = {})
request = self.request if respond_to?(:request)
- host = config.asset_host if defined? config.asset_host
+ host = options[:host]
+ host ||= config.asset_host if defined? config.asset_host
host ||= request.base_url if request && options[:protocol] == :request
if host.respond_to?(:call)