Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  1. How come Heroku compile assets files to /tmp?
  2. 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?
like image 208
aquajach Avatar asked Mar 12 '13 06:03

aquajach


People also ask

What is assets precompile in Rails?

The Rails asset pipeline provides an assets:precompile rake task to allow assets to be compiled and cached up front rather than compiled every time the app boots. There are two ways you can use the asset pipeline on Heroku. Compiling assets locally. Compiling assets during slug compilation.

What is asset pipeline Rails?

The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages and pre-processors such as CoffeeScript, Sass, and ERB.

What does rake assets Clean do?

The rake assets:clean task allows for rolling deploys that may still be linking to an old asset while the new assets are being built. If you want to clear public/assets completely, you can use rake assets:clobber . Show activity on this post. Note: rake assets:clobber also removes the assets directory completely.


2 Answers

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 
like image 151
Joseph Ravenwolfe Avatar answered Sep 25 '22 06:09

Joseph Ravenwolfe


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  
like image 39
Israel Barba Avatar answered Sep 23 '22 06:09

Israel Barba