Sunday, 4 August 2013

Rails4, Phusion Passenger, asset pipeline problems

Rails 4 has introduced many new and exciting features, but it's very new technology and one of the most important features, asset pipelines is causing many people headaches. If you use Phusion Passenger with Rails 4 and Ruby 2, you may encounter these problems:

  1. Pre-compiled fingerprints used for some assets, but not others.
  2. Mismatch between pre-compiled hashes and the hashes that production assigns (i.e. fingerprint mismatches) not resolved by re-compiling the assets.
Usually you will get a message that looks like this:
ActionController::RoutingError (No route matches [GET]
with the asset following in quotes.

We found that the following helped resolve the problems:
  • Append "RAILS_ENV=production RAILS_GROUPS=assets" to your rake assets:precompile line. I.e.: bundle exec rake assets:precompile RAILS_ENV=production RAILS_GROUPS=assets
In config/environments/production.rb:
  • Make Rails use digest: config.assets.digest = true
  • Enable fallback to assets pipeline: config.assets.compile =true
Hopefully in time Rails 4 pipeline issues will be resolved, but for now, these work-arounds in some environments seem to be the best way to ensure that assets remain served in production.
 

4 comments:

  1. Thanks for sharing, but these steps didn't work for me. Are you aware of an associated Rails or Passenger bug/

    ReplyDelete
    Replies
    1. Not that I am aware of, sorry! Please post here if you solve it so that others can benefit!

      Delete