Rails 3.1 Static Asset – Must Assets by Precompiled for Productions

asset-pipelineruby-on-rails-3.1

My understanding of new Rails 3.1 asset pipeline in production mode is as follows:->

  1. config.action_controller.asset_host = "https://mybucket.s3.amazonaws.com"
  2. config.assets.compile = false
  3. app/assets are checked into repo
  4. bundle exec rake assets:precompile and sync with S3 (all assets)
  5. public/assets is NOT checked into repo

With all the above, I thought Rails would look for all the assets on S3 and I don't need them in the repository. Or at least I don't need the precompiled assets in public/assets in the repo.

I have found this, on heroku, if don't have config.assets.compile = true, it flat out will not find the precompiled assets on S3. And heroku must run through a compiling phase for all assets, but then will server them out of S3. Running heroku run rake assets:precompile doesn't do squat. The production process will re-compile everything again.

Huh? That makes no sense to me.

I would make sense to me that you do not need to fill your repo with images, let your CDN do the work.

I have a feeling this is incorrect. Am I right or wrong?

Best Answer

When you have this set:

config.assets.compile = false

no requests for assets will be passed to Sprockets to be served. It is expected that the files will be precompiled somewhere.

Check out the asset pipeline setup guide on the Heroku site as there is a special setup to get it working.