aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/asset_tag_helper.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-01-06 20:53:23 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2008-01-06 20:53:23 +0000
commita1b0349362fd6c17af5aeff481996f6fac235828 (patch)
treeacae9550ddae5e678618b9eb79ffc3bbf00b5c23 /actionpack/lib/action_view/helpers/asset_tag_helper.rb
parentca4c7ab362d0110bfade496ca66b30bafdb7f25e (diff)
downloadrails-a1b0349362fd6c17af5aeff481996f6fac235828.tar.gz
rails-a1b0349362fd6c17af5aeff481996f6fac235828.tar.bz2
rails-a1b0349362fd6c17af5aeff481996f6fac235828.zip
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
Diffstat (limited to 'actionpack/lib/action_view/helpers/asset_tag_helper.rb')
-rw-r--r--actionpack/lib/action_view/helpers/asset_tag_helper.rb26
1 files changed, 23 insertions, 3 deletions
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")
# => <link href="http://assets1.example.com/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />
#
- # The proc takes a single <tt>source</tt> 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 <tt>source</tt> parameter (which is the path of the source asset) and an optional
+ # <tt>request</tt> parameter (which is an entire instance of an <tt>ActionController::AbstractRequest</tt>
+ # 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")
# => <link href="http://assets.example.com/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />
#
+ # The optional <tt>request</tt> 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