2

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

像这样的东西:

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
4

1 回答 1

-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
于 2012-08-29T14:59:16.740 回答