Confusion about rake assets:clean / cleanup on the asset pipeline in rails

daniel picture daniel · Feb 17, 2012 · Viewed 56.3k times · Source

Could somebody explain to me what the command rake assets:clean really does? Unfortunately the Rails Guides dont mention it. There is also the command rake assets:cleanup. Whats the difference?

Furthermore could somebody tell me when do I have to run rake assets:precompile in production. Do I run it on the server console after I deployed all my application files to my production server? Or do I precompile on my local machine and then do a deploy of all files?

Thanks all

Answer

Sergio Tulentsev picture Sergio Tulentsev · Feb 17, 2012

Note: This answer is rails 3 specific. For rails 4 and later, look at other answers here.

If you precompile on your local machine, then you can commit these generated assets into the repository and proceed with deployment. No need to compile them on production machine.

But it introduces a problem: now when you change source files (coffescript / scss), the app won't pick up the changes, because it will serve precompiled files instead. rake assets:clean deletes these precompiled files.

In my projects assets are precompiled as a part of deployment. Capistrano makes it very easy.

Also, I never heard of rake assets:cleanup.