config.action_controller.asset_host仅适用于动态资产?

时间:2013-05-11 06:13:07

标签: ruby-on-rails ruby-on-rails-3 asset-pipeline

我正在使用asset_sync gem在亚马逊s3上托管我的资产。我已经设置了config.action_controller.asset_host来指向我的s3存储桶,以便它将从s3提供我的资产。

但是,只有我的动态生成的资产从s3提供,其他静态资产(如图像)不是从s3提供的,它们只是从相对目录“/assets/filename.ext”提供。

如何让rails将s3用于我的静态资产,而不仅仅是动态生成的资产?

这是我的生产环境文件:

config.cache_classes = true

# Full error reports are disabled and caching is turned on  
config.consider_all_requests_local       = false  
config.action_controller.perform_caching = true

# Disable Rails's static asset server (Apache or nginx will already do this)   
config.serve_static_assets = false

# Compress JavaScripts and CSS   
config.assets.compress = true

# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = true

# Generate digests for assets URLs   
config.assets.digest = true

ENV['FOG_DIRECTORY'] = 'bucket'   
ENV['AWS_ACCESS_KEY_ID'] = 'key'   
ENV['AWS_SECRET_ACCESS_KEY'] = 'key'
config.action_controller.asset_host = "http://bucket.s3.amazonaws.com"

config.assets.prefix = "/assets"

config.assets.initialize_on_precompile = true

1 个答案:

答案 0 :(得分:0)

您需要在production.rb

中设置以下内容

ActionController::Base.asset_host = "http://bucket.s3.amazonaws.com"