Search code examples
ruby-on-railsherokuasset-pipeline

Why heroku clean assets after precomipling them?


I am new to Rails.When I was deploying app to heroku,terminal showed such informations:

remote: -----> Detecting rake tasks
remote: -----> Preparing app for Rails asset pipeline
remote:        Running: rake assets:precompile
remote:        I, [2017-05-10T05:03:15.348460 #1268]  INFO -- : Writing     /tmp/build_6d070dbb68ed231a9980e7d6aee4630f/public/assets/fore- 1ea7b4ae84fb4d285d3da11143e3367c41cf15e8e44b9dba475b4b572fc7ae74.png

remote:        I, [2017-05-10T05:03:15.370482 #1268]  INFO -- : Writing /tmp/build_6d070dbb68ed231a9980e7d6aee4630f/public/assets/subdirectory/image-B-f3b8e56853071297fbe1da778049948f40f87756705420a97a157e9cf8a477be.jpg
...

remote:        Asset precompilation completed (12.71s)
remote:        Cleaning assets
remote:        Running: rake assets:clean

We saw that the app/assets/ has been precompiled, including images and subdirectory. But when I open the website on heroku, all the images under app/assets/ failed.

To solve this, I ran RAILS_ENV=production rake assets:precompile, check in git, push again. Then the images showed the right way.

My quesiton is:

Why rails clean assets after assets precompilation completed(see the end of the information).I didn't change any default configuration. Does this only happen in heroku?

Must I run precompile locally before deploying? Every time?


Solution

  • config/production.rb

    config.assets.compile = true
    

    Run following commands:

    RAILS_ENV=production rake assets:precompile
    

    then push all files & manifest file to heroku.