简体   繁体   中英

Rails 4 with asset_sync

Has anyone got the asset_sync gem to work with Rails 4? I have never had a problem with it with Rails 3, but i cannot precompile my assets to my S3 bucket anymore, what happens is everything is just compiled into my public folder.

Could anyone offer advice on resources to look at or summarise the key differences between Rails 3 and 4 that would cause this to fail. Some examples of configuration used would be helpful from those who have got it working. I am at a loss on how to start debugging this

Any advice and help appreciated

Thanks

EDIT

Current config

# Within Initializer #在初始化器中

if defined?(AssetSync)
 AssetSync.configure do |config|
  config.fog_provider = ENV['FOG_PROVIDER']
  config.aws_access_key_id = ENV['AWS_ACCESS_KEY_ID']
  config.aws_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
  config.fog_directory = ENV['FOG_DIRECTORY']
  config.fog_region = ENV['FOG_REGION']
  config.existing_remote_files = "delete"
  config.gzip_compression = true
  config.manifest = true
  config.custom_headers = { '.*' => { cache_control: 'max-age=315576000', expires: 1.year.from_now.httpdate } }
 end
end

Production.rb

YmcaView::Application.configure do

config.action_controller.asset_host = "//#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com"
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local       = false
config.action_controller.perform_caching = true
config.serve_static_assets = true 
config.assets.js_compressor = :uglifier
config.assets.compile = true
config.assets.digest = true
config.assets.version = '1.0'
config.log_level = :info
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
end

Output when running rake assets:precompile RAILS_ENV=production

 I, [2014-03-04T13:04:41.176230 #6085]  INFO -- : Writing /home/richardlewis/Rails/ymca_view/public/assets/760x380_10-477c3cdc939905d6b32f9997e7f93072.jpg
 I, [2014-03-04T13:04:41.177963 #6085]  INFO -- : Writing /home/richardlewis/Rails/ymca_view/public/assets/aboutus-d9ad504fcd86071255015d24780caef8.jpg
 I, [2014-03-04T13:04:45.018794 #6085]  INFO -- : Writing /home/richardlewis/Rails/ymca_view/public/assets/application-90d317f561a8b0e84124ce7bb872f867.js
 I, [2014-03-04T13:04:46.666640 #6085]  INFO -- : Writing /home/richardlewis/Rails/ymca_view/public/assets/application-b422f803b56ae2f5c56a648891ec553e.css
 [fog][WARNING] Unable to load the 'unf' gem. Your AWS strings may not be properly encoded.

Yep we've got it working in Rails 4

You need to do this:

#GemFile (might need aws_sdk gem too)
gem "asset_sync", "~> 1.0.0"

#config/environments/production.rb
config.action_controller.asset_host = "//#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com"

$-> rake assets:precompile RAILS_ENV=production

We use Figaro to store ENV vars locally, here's what we got:

#config/application.yml
FOG_DIRECTORY: "***BUCKET_NAME****"
FOG_PROVIDER: "AWS"
FOG_REGION: "eu-west-1"
ASSET_SYNC_GZIP_COMPRESSION: "true"
ASSET_SYNC_MANIFEST: "true"
ASSET_SYNC_EXISTING_REMOTE_FILES: "delete"

I didn't need to use the 1.0.0 version. I used the latest gem, it seems that it doesn't actually upload (at least on EY) when it is in the :assets group. I had to add it to the general group in my Gemfile and it worked fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM