From a1b0349362fd6c17af5aeff481996f6fac235828 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 6 Jan 2008 20:53:23 +0000 Subject: The asset_host block takes the controller request as an optional second argument. Example: use a single asset host for SSL requests. Closes #10549. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8578 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../lib/action_view/helpers/asset_tag_helper.rb | 26 +++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'actionpack/lib/action_view/helpers/asset_tag_helper.rb') diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index ba474a8ffe..fd01fd60bc 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -50,8 +50,10 @@ module ActionView # stylesheet_include_tag("application") # => # - # The proc takes a single source parameter which is the path of the source asset. This can be used to - # generate a particular asset host depending on the asset path. + # The proc takes a source parameter (which is the path of the source asset) and an optional + # request parameter (which is an entire instance of an ActionController::AbstractRequest + # subclass). This can be used to generate a particular asset host depending on the asset path and the particular + # request. # # ActionController::Base.asset_host = Proc.new { |source| # if source.starts_with?('/images') @@ -65,6 +67,19 @@ module ActionView # stylesheet_include_tag("application") # => # + # The optional request parameter to the proc is useful in particular for serving assets from an + # SSL-protected page. The example proc below disables asset hosting for HTTPS connections, while still sending + # assets for plain HTTP requests from asset hosts. This is useful for avoiding mixed media warnings when serving + # non-HTTP assets from HTTPS web pages when you don't have an SSL certificate for each of the asset hosts. + # + # ActionController::Base.asset_host = Proc.new { |source, request| + # if request.ssl? + # "#{request.protocol}#{request.host_with_port}" + # else + # "#{request.protocol}assets.example.com" + # end + # } + # # === Using asset timestamps # # By default, Rails will append all asset paths with that asset's timestamp. This allows you to set a cache-expiration date for the @@ -461,7 +476,12 @@ module ActionView def compute_asset_host(source) if host = ActionController::Base.asset_host if host.is_a?(Proc) - host.call(source) + case host.arity + when 2: + host.call(source, @controller.request) + else + host.call(source) + end else host % (source.hash % 4) end -- cgit v1.2.3