From 356dbf62c8a896d62f4a3149b796eee925ff190b Mon Sep 17 00:00:00 2001 From: Chris Hapgood Date: Wed, 10 Sep 2008 17:40:09 -0400 Subject: [PATCH] Ensured compute_asset_host always returns an appropriate value. --- actionpack/lib/action_controller/base.rb | 2 +- .../lib/action_view/helpers/asset_tag_helper.rb | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 670a049..1c1b0e7 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -269,7 +269,7 @@ module ActionController #:nodoc: # Prepends all the URL-generating helpers from AssetHelper. This makes it possible to easily move javascripts, stylesheets, # and images to a dedicated asset server away from the main web server. Example: # ActionController::Base.asset_host = "http://assets.example.com" - @@asset_host = "" + @@asset_host = nil cattr_accessor :asset_host # All requests are considered local by default, so everyone will be exposed to detailed debugging screens on errors. diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index ed33f08..d39be83 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -520,17 +520,19 @@ module ActionView # numbers 0-3 if it contains %d (the number is the source hash mod 4), # or the value returned from invoking the proc if it's a proc. def compute_asset_host(source) - if host = ActionController::Base.asset_host - if host.is_a?(Proc) - case host.arity - when 2 - host.call(source, @controller.request) - else - host.call(source) - end + case host = ActionController::Base.asset_host + when Proc + case host.arity + when 2 + host.call(source, @controller.request) else - (host =~ /%d/) ? host % (source.hash % 4) : host + host.call(source) end + when String + (host =~ /%d/) ? host % (source.hash % 4) : host + when NilClass +# host.blank? ? url_for(:use_route => :root, :only_path => false) : host + respond_to?(:root_url) ? root_url : host end end -- 1.6.0