Heroku does NOT compile files under assets pipelines in Rails 4

Everything goes well in local machine with assets pipeline in Rails 4 and Ruby 2.0. But when deploying to heroku, it is shown that:

-----> Preparing app for Rails asset pipeline
   Running: rake assets:precompile
   I, [2013-03-12T03:28:29.908234 #912]  INFO -- : Writing /tmp/build_1n6yi8lwna3sj/public/assets/rails-2ee5a98f26fbf8c6c461127da73c47eb.png
   I, [2013-03-12T03:28:29.914096 #912]  INFO -- : Writing /tmp/build_1n6yi8lwna3sj/public/assets/trash-3c3c2861eca3747315d712bcfc182902.png
   I, [2013-03-12T03:28:33.963234 #912]  INFO -- : Writing /tmp/build_1n6yi8lwna3sj/public/assets/application-bf2525bd32aa2a7068dbcfaa591b3874.js
   I, [2013-03-12T03:28:40.362850 #912]  INFO -- : Writing /tmp/build_1n6yi8lwna3sj/public/assets/application-13374a65f29a3b4cea6f8da2816ce7ff.css
   Asset precompilation completed (14.36s)

Heroku seems to compile files but put it in /tmp without any errors. My questions are:

  • How come Heroku compile assets files to /tmp?
  • My last solution was to run RAILS_ENV=production bundle exec rake assets:precompile locally, but this generated a manifest-xxxxxx.json in public/assets, rather than manifest.yml, so that heroku doesn't detect the JSON manifest file. I sorted it out by manually created a yml from the json file and heroku became happy. Has heroku's approach been outdated?

  • Heroku's asset plugins no longer work since Rails 4 does not support plugins. You need to use Heroku's asset gems instead. Place this in your Gemfile:

    group :production do
      gem 'rails_log_stdout',           github: 'heroku/rails_log_stdout'
      gem 'rails3_serve_static_assets', github: 'heroku/rails3_serve_static_assets'
    end
    

    Follow Heroku's guide on getting started with Rails 4.

    Update (07/22/2013): Heroku now supplies a different gem to precompile assets.

    group :production do
      gem 'rails_12factor'
    end
    

    You need to config Rails to serve static assets in production: config/environments/production.rb

    SampleApp::Application.configure do
      .
      .
      .
      config.serve_static_assets = true
      .
      .
      .
    end
    

    UPDATE:

    In Rails 4 is deprecated, and has been changed by:

    config.serve_static_files = true 
    

    Since rails 4 replaced manifest.yml with manifest-(fingerprint).json, you'll want to enable static asset serving.

    From Getting Started with Rails 4.x on Heroku:

    gem 'rails_12factor', group: :production
    

    then

    bundle install
    

    and, finally,

    git push heroku
    

    Fixed the issue for me. Hope this helps!

    链接地址: http://www.djcxy.com/p/79990.html

    上一篇: 未初始化的常量AssetSync

    下一篇: Heroku不会在Rails 4的资产管道下编译文件