[英]Set a different asset host for a specific asset_path in Rails 3.1
Does anyone know if it's possible to somehow set a different asset_host for a asset that is addressed using the asset_path or asset_url helper method? 有谁知道是否有可能为使用asset_path或asset_url帮助器方法寻址的资产设置不同的asset_host?
Something like this: 像这样:
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
This can be achieved by doing the following: 这可以通过执行以下操作来实现:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.