2012-08-23 18 views
2

有谁知道是否有可能以某种方式为使用asset_path或asset_url辅助方法寻址的资产设置不同的asset_host?在Rails 3.1中为特定asset_path设置不同的资产主机

事情是这样的:

asset_path 'path/to/asset.html', :host => nil #this will same sure the asset is on the same domain 
asset_path 'path/to/asset.jpg', :host => 'http://staticserver.com' #static server 

回答

-1

这可以通过执行来实现以下几点:

def custom_asset_path(asset) 
    config = MyApp::Application.config.action_controller 
    asset_host = config.asset_host 
    config.asset_host = "http://custom-asset-server.com" 
    path = asset_path(asset) 
    config.asset_host = asset_host 
    path 
end 
+1

这将在多线程ENV突破 – Yevgeniy