2

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

asset_sync.rb # 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.
Richlewis
  • 15,070
  • 37
  • 122
  • 283
  • Try with config/asset_sync.yml http://www.codebeerstartups.com/2012/10/how-to-deploy-assets-on-amazon-s3-and-why-deploying-assets-to-amazon-s3-is-important/#.UxW1iKCJatI it should work – user2503775 Mar 04 '14 at 11:17

2 Answers2

2

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"
Richard Peck
  • 76,116
  • 9
  • 93
  • 147
  • thanks @RichPeck, so no other configuration changes are needed in application.rb with regards to assets.digest and production,rb stays as default ? and if i wanted to try this out in development just use same code in that environment? – Richlewis Mar 04 '14 at 11:28
  • Yep I think that will work. Although Asset_Sync is really for precompiled assets -- if you're in development (typically on local machine), your assets are compiled ad-hoc – Richard Peck Mar 04 '14 at 11:33
  • ok so i tried what you suggested in production, but again the assets have compiled into the public directory and asset_sync was once again ignored..... – Richlewis Mar 04 '14 at 12:59
  • Have you installed the gem? Are you sure you've connected your S3 bucket correctly? I can make a video of the thing working for us right now if you want? – Richard Peck Mar 04 '14 at 13:00
  • 1
    I dont doubt you for a second, just not sure what im doing wrong, ill post my output in the question along with my config, maybe you could spot something? – Richlewis Mar 04 '14 at 13:02
  • question updated with my config, im getting no errors to say that there is anything wrong with my Credentials for S3 bucket – Richlewis Mar 04 '14 at 13:12
  • The `unf` gem thing means it's being called! Have you checked your S3 bucket? The gem `syncs` (which means it will create the precompiled assets then upload them. Is your bucket getting populated? – Richard Peck Mar 04 '14 at 13:23
  • now i feel stupid, they are all in there, so maybe it was working all along....hmmm, though the reason i was confused was that normally you see output like this AssetSync: using default configuration from built-in initializer AssetSync: Syncing. Uploading: assets/application-34cec68e88b51431f93033c2d4d78bfb.css Thank you for being patient and assisting me though – Richlewis Mar 04 '14 at 13:28
  • no probs buddy! Hope everything is moving forward for you? The Asset Sync gem is really nice, but you're right in that is a silent assassin -- operating without notice – Richard Peck Mar 04 '14 at 13:38
  • getting there, next problem though, fonts and svgs not being served now :-( shall persevere – Richlewis Mar 04 '14 at 13:38
  • How are you calling them? – Richard Peck Mar 04 '14 at 13:53
  • well there are 2 problems i notice, if an image is a background image within my css file then that's not showing and the fonts are @font-face with icomoon icons... i have a folder called fonts within app/assets/ – Richlewis Mar 04 '14 at 14:00
  • Have you called them with CSS or SCSS? You'll need to use SCSS because that will allow you to use `asset_url` to use the dynamically generated path (for digest / fingerprinted assets) – Richard Peck Mar 04 '14 at 14:02
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/48960/discussion-between-richlewis-and-rich-peck) – Richlewis Mar 04 '14 at 14:04
1

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.

Cory
  • 63
  • 1
  • 7
  • I experienced the same. Moving the `asset_sync` gem out of the assets group in the Gemfile solved the problem. This is because rails removed the assets group when moving to rails 4.0 : http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-3-2-to-rails-4-0-gemfile – Shadwell Nov 14 '14 at 13:13