Uninitialized AssetSync constant

I used gem asset_sync and aws to precompile my assets. rake assets: precompilation works fine. After I clicked my application on the hero, and

heroku run rake db:migrate 

I get the following error

"uninitialized constant AssetSync"

Initializers / asset_sync.rb

 AssetSync.configure do |config| config.fog_provider = 'AWS' config.aws_access_key_id = "..." config.aws_secret_access_key = "..." config.fog_directory = Rails.env + "-..." config.fog_region = 'eu-west-1' end 

configurations / production.rb

 config.action_controller.asset_host = "//#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com" config.assets.enabled = true 

After running run rake assets: precompiling for the first time, all my applications / assets / images were transferred to public / assets. I removed them from github and added public / assets / * to .gitignore. Maybe this is a problem?

Editing: when git starts, click the hero wizard, it looks like they were precompiled

  Preparing app for Rails asset pipeline Running: rake assets:precompile AssetSync: using /tmp/build_2ltvklj0gaxjp/config/initializers/asset_sync.rb AssetSync: using /tmp/build_2ltvklj0gaxjp/config/initializers/asset_sync.rb AssetSync: Syncing. Using: Directory Search of /tmp/build_2ltvklj0gaxjp/public/assets Uploading: assets/application-7e17d9f0ed9cb7ea50b750e2bfc7e28c.css.gz Uploading: assets/application-7e17d9f0ed9cb7ea50b750e2bfc7e28c.css AssetSync: Done. Asset precompilation completed (58.04s) 
+6
source share
1 answer

Your initializer assumes that AssetSync is always defined, but this will not be the case if your Gemfile looks like this:

 group :assets do gem 'asset_sync' end 

asset_sync documentation recommends wrapping the initializer in:

 if defined?(AssetSync) ... end 

This is because Heroku operates production without the assets of a gem group. Heroku will precompile your assets when push is launched - and if asset_sync turned on, it will update S3 at that time - so when your application starts later, it no longer needs these gems. Thus, your asset_sync initializer should handle the situation when the stone is not loaded.

+13
source

All Articles