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

Ruby on-RailsRuby on-Rails-3Asset Pipeline

Ruby on-Rails Problem Overview


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

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

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.

Solution 2 - Ruby on-Rails

Run rake assets:clobber to actually clean the assets. http://www.dixis.com/?p=735

Solution 3 - Ruby on-Rails

Sergio's answer was completely correct in Rails 3. rake assets:clean deleted all assets that had been previously precompiled into the public/assets directory.

In Rails 4, you run rake assets:clobber to do the same thing.

If you run rake assets:precompile with the following config (by default turned on in staging and production):

# config/environments/production.rb
config.assets.digest = true

You compiled assets get timestamped. This means you can compile your new assets while leaving the old assets in place. You usually want to do this in production so you website will still access the old files while your running precompile to create your new files (because you've added new css/javascript). You now want to get rid of the old files that are no longer in use. The clean it removes the old versions of the precompiled assets while leaving the new assets in place.

Solution 4 - Ruby on-Rails

rake assets:clean removes compiled assets. It is run by cap deploy:assets:clean to remove compiled assets, generally from a remote server.

cap deploy:clean removes old releases, generally from a remote server. It is not rake assets:clean

rake != cap

Solution 5 - Ruby on-Rails

rake assets:clean is now run by cap deploy:cleanup_assets. Add require 'capistrano/rails/assets' to your Capfile and you get this cap-task. My capistrano version is v3.2.1.

Solution 6 - Ruby on-Rails

clean up those untracked files with git clean -f for files and git clean -f -d for directories

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondanielView Question on Stackoverflow
Solution 1 - Ruby on-RailsSergio TulentsevView Answer on Stackoverflow
Solution 2 - Ruby on-RailsFahim Babar PatelView Answer on Stackoverflow
Solution 3 - Ruby on-RailsgrouchomcView Answer on Stackoverflow
Solution 4 - Ruby on-Railspaul.beltView Answer on Stackoverflow
Solution 5 - Ruby on-RailsdduftView Answer on Stackoverflow
Solution 6 - Ruby on-RailsjacaView Answer on Stackoverflow