There is a nice feature in the action controller controller class that allows you to set an asset host. Its useful if you do not want to host your css, image, and javascript on the same server. Easy as pie to set
ActionController::Base.asset_host = "assets.mycoolapp.com"
conifg.action_controller.asset_host = "assets.mycoolapp.com"
There is also a nice little plugin for rails call
AssetPacker. It does some nice things like strip out white spaces and other things I should care about. But the point of this post is that these two concepts does not play well with each other.. Not yet at least..
Patch: asset_packager / lib / synthesis / asset_package_helper.rb
Current:
private
def compute_public_path(source, dir, ext=nil, add_asset_id=true)
source = source.dup
source << ".#{ext}" if File.extname(source).blank? && ext
unless source =~ %r{^[-a-z]+://}
source = "/#{dir}/#{source}" unless source[0] == ?/
asset_id = rails_asset_id(source)
source << '?' + asset_id if defined?(RAILS_ROOT) and add_asset_id and not asset_id.blank?
source = "#{ActionController::Base.asset_host}#{@controller.request.relative_url_root}#{source}"
end
source
end
Soon To Beish:
private
def compute_public_path(source, dir, ext=nil, add_asset_id=true)
source = source.dup
source << ".#{ext}" if File.extname(source).blank? && ext
unless source =~ %r{^[-a-z]+://}
source = "/#{dir}/#{source}" unless source[0] == ?/
asset_id = rails_asset_id(source)
source << '?' + asset_id if defined?(RAILS_ROOT) and add_asset_id and not asset_id.blank?
source = "#{asset_package_host(source)}#{@controller.request.relative_url_root}#{source}"
end
source
end
def asset_package_host(source)
if self.respond_to?(:compute_asset_host,true)
eval("def asset_package_host(source)\n compute_asset_host(source)\n end")
else
eval("def asset_package_host(source)\n {ActionController::Base.asset_host\n end")
end
end
I am going to use git hub to submit a patch to the author SBECKER! But I wanted to write it down before I forgot. This was written a text area in firefox. It is untested and not checked for syntax. I should have a git hub fix patch up soon cause I have very little to do tomorrow.
I do believe this kind of rewriting of a method on the fly makes it 3 times harder to debug but in the case it is 100% more useful.
[Update]
I failed to highlight the real issue. Asset host allows for 4 asset hosts. There is a method in Rails 2.0+ that will create asset0.host.com, asset1.host.com... and round robin the asset names. There are many sites on why this is good. The problem with the asset packer is that it redeclares compute_public_path. I am ok with that but it was leaving out a feature I wanted. I contacted sbecker on github and committed my patch to a fork.
http://github.com/sbeckeriv/asset_packager/tree/master I am still new to github but I think I did everything ok. It turns out I can not run the rake test. It requires an extra rails project sbecker must have set up.