Richard Stokes
Richard Stokes

Reputation: 3552

Upgrading to Rails 3.1 Asset Pipeline proving problematic

I'm trying to upgrade an app that's already deployed to Heroku to use the asset pipeline in Rails 3.1. I followed all the necessary steps in RailsCasts #282 and my app runs fine locally. However, when I push to Heroku and try to access the root path, I'm getting errors of the sort "foobarbaz.png" is not precompiled. If I remove the first image from the page, I get the same error for the next one down, and so on. All the images have been pushed to Heroku, so there's no case of trying to reference images that aren't there.

I noticed that when I pushed the app to Heroku, I did/do not see the following output:

-----> Preparing Rails asset pipeline
       Running: rake assets:precompile

I've tried running rake assets:precompile locally and keep getting the following error:

rake aborted!
production database is not configured

There's no production configuration in my database.yml file due to using Heroku. When I try to run heroku run rake assets:precompile, I get the following error:

rake aborted!
Application has been already initialized.

I've added the necessary lines to application.rb and my environment files, and I just can't seem to get it working!

Upvotes: 0

Views: 175

Answers (2)

frankmt
frankmt

Reputation: 133

That problem happened to me as well, and in my case it was because I had the following line on my config/application.rb

config.assets.initialize_on_precompile = false

It seems to be needed in some versions of Rails according to Heroku (https://devcenter.heroku.com/articles/rails-asset-pipeline),

While precompiling assets, in Rails 3.x, you can prevent initializing your application and connecting to the database by ensuring that the following line is in your config/application.rb:

config.assets.initialize_on_precompile = false

but in my case it was throwing the 'Application already initialized' exception, and that went away after I've removed it

Since Heroku logs weren't really helpful when deploying, the way I've tested it was to run the assets precompile rake task on my heroku instance:

heroku run rake assets:precompile

Upvotes: 2

Brian Petro
Brian Petro

Reputation: 1567

Heroku assumes you are doing your own precompiling (which you are having a problem with) if the file manifest.yml is present.

REMOVE manifest.yml from your public or public/assets folder.

Push the changes to heroku. Example below.

$ git rm public/assets/manifest.yml
$ git commit -m "remove precompile manifest"
$ git push -f heroku master

Run assets:precompile on heroku server. Enter:

$ heroku run rake assets:precompile

Upvotes: 1

Related Questions