Rails / Heroku / Cloudcontrol: Precompiled assets manifest ignored

147 Views Asked by At

I am currently troubleshooting an issue with precompiling of asset pipeline and pushing it on the server. I am on rails 4.2.3 and ruby 2.2.0!

I precompile my assets with

RAILS_ENV=production bundle exec rake assets:precompile

and several files are created successfully, including the .sprockets-manifest-... file.

If i now try to push the app, it looks like the manifest file is not detected - my usual "assets cannot be compiled" issue (the reason why i am precompiling) occurs:

   Preparing app for Rails asset pipeline
   Running: rake assets:precompile
   rake aborted!
   Mysql2::Error: Can't connect to MySQL server on '127.0.0.1' (111)

I am pretty sure this worked before but somehow - maybe by upgrading to rails 4.2.3, it fails now...

I appreciate any kind of help!

2

There are 2 best solutions below

0
bgeek On BEST ANSWER

The usage of the sprockets gem with a version < 3.x fixes this issue for me.

With the new version (> 3.x), the name of the manifest file has changed to .sprockets-manifest-xxxx.json! Due to this the precompiled assets aren't recognized correctly. With the old version the old name .manifest-xxxx.json is used and the precompiled assets are recognized.

6
pst On

The Add-on credentials, like databases are not available during build. On cloudControl you can detect if you're inside the build process by reading the BUILDPACK_RUNNING environment variable. See the Rails notes for an example.

The recommended way is to have the buildpack compile the assets during push. But you need to make sure Rails is not trying to connect to the database. Here's a related SO question regarding this.

If you want to precompile locally and this is not being detected I'd suggest to check if the manifest and the precompiled assets have been committed to the repository. A common pitfall is the .gitignore file.