I have used the asset_sync gem many times before with great success, but using it in a Rails 4.0.3 project seems to have caused a problem.
The assets are uploaded, hashed and gzipped to the target directory (I just went with the default 'assets'), but when running the application in staging/production environment the paths are incorrect.
They take on the form:
S3_DOMAIN.com/stylesheets/application.css
Instead of:
S3_DOMAIN.com/assets/application-HASH.css
Has anyone else experienced this problem? The only way I have found to reverse this behaviour is to set config.assets.compile to true, but this won't do in a production environment.
Here are the relevant config files:
## environments/staging.rb
config.serve_static_assets = false
config.assets.compress = true
config.assets.js_compressor = :uglifier
config.assets.css_compressor = :sass
# Have to set this to true to make asset_sync generate the correct links
config.assets.compile = false
config.assets.digest = true
config.assets.enabled = true
config.assets.initialize_on_precompile = true
config.action_controller.asset_host = "//#{Figaro.env.fog_directory}.s3.amazonaws.com"
config.action_mailer.asset_host = "//#{Figaro.env.fog_directory}.s3.amazonaws.com"
config.assets.prefix = "/assets"
config.assets.debug = false
config.assets.cache_store = :memory_store
##config/asset_sync.yml
defaults: &defaults
fog_provider: 'AWS'
aws_access_key_id: "<%= ENV['AWS_ACCESS_KEY_ID'] %>"
aws_secret_access_key: "<%= ENV['AWS_SECRET_ACCESS_KEY'] %>"
# To use AWS reduced redundancy storage.
# aws_reduced_redundancy: true
# You may need to specify what region your storage bucket is in
fog_region: <%= ENV['FOG_REGION'] %>
existing_remote_files: keep
# To delete existing remote files.
# existing_remote_files: delete
# Automatically replace files with their equivalent gzip compressed version
gzip_compression: true
# Fail silently. Useful for environments such as Heroku
# fail_silently: true
development:
<<: *defaults
enabled: false
test:
<<: *defaults
enabled: false
staging:
<<: *defaults
fog_directory: <%= ENV['FOG_DIRECTORY'] %>
production:
<<: *defaults
fog_directory: <%= ENV['FOG_DIRECTORY'] %>