aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2012-10-12 17:07:17 -0500
committerJoshua Peek <josh@joshpeek.com>2012-10-12 17:07:17 -0500
commitc3cff4d4219c556a5bfe4cbd72b96723b1633122 (patch)
treec7d06552789267c7d8014129f103644c51364de8 /actionpack/lib/action_view
parent1e2b0ce95e48463361111ceae6eed7d4ad5462f0 (diff)
downloadrails-c3cff4d4219c556a5bfe4cbd72b96723b1633122.tar.gz
rails-c3cff4d4219c556a5bfe4cbd72b96723b1633122.tar.bz2
rails-c3cff4d4219c556a5bfe4cbd72b96723b1633122.zip
Ensure AssetUrlHelper can be mixed into AC::Base
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r--actionpack/lib/action_view/helpers/asset_url_helper.rb19
1 files changed, 13 insertions, 6 deletions
diff --git a/actionpack/lib/action_view/helpers/asset_url_helper.rb b/actionpack/lib/action_view/helpers/asset_url_helper.rb
index 8cbcdfe99e..f2213efbb9 100644
--- a/actionpack/lib/action_view/helpers/asset_url_helper.rb
+++ b/actionpack/lib/action_view/helpers/asset_url_helper.rb
@@ -135,8 +135,7 @@ module ActionView
source = compute_asset_path(source, options)
end
- current_request = controller.request if controller.respond_to?(:request)
- if relative_url_root = config.relative_url_root || current_request.try(:script_name)
+ if relative_url_root = config.relative_url_root || asset_request.try(:script_name)
source = "#{relative_url_root}#{source}" unless source.starts_with?("#{relative_url_root}/")
end
@@ -180,10 +179,7 @@ module ActionView
# or the value returned from invoking call on an object responding to call
# (proc or otherwise).
def compute_asset_host(source = "", options = {})
- if controller.respond_to?(:request)
- request = controller.request
- end
-
+ request = asset_request
host = config.asset_host
host ||= request.base_url if request && options[:protocol] == :request
return unless host
@@ -342,6 +338,17 @@ module ActionView
url_to_asset(source, type: :font)
end
alias_method :url_to_font, :font_url # aliased to avoid conflicts with an font_url named route
+
+ private
+ # Get current request if self is a controller. If self is a
+ # view, check the parent controller's request.
+ def asset_request
+ if respond_to?(:request)
+ request
+ elsif respond_to?(:controller) && controller.respond_to?(:request)
+ controller.request
+ end
+ end
end
end
end