7
votes

I'm having a bit of trouble getting my asset pipeline setup working with Heroku/Cedar using Rails 3.1.1

I've pushed my application and it launches successfully but there was no message that said "Preparing asset pipeline" and no static assets are being served up. No JS, CSS, or images are able to be found as there is no slug compilation time or runtime asset compilation being done.

Any help would be greatly appreciated.

They describe what should happen during deployment at this link which I'll summarize below:

With a Rails 3.1 application on Heroku Cedar when you git push heroku your assets will all be pre-compiled as part of the deploy process by using the rake task bundle exec rake assets:precompile.

2
just a minor point - If you've already precompiled your assets locally, committed to git and pushed to Heroku and a manifest file exists in public/assets then Heroku will NOT attempt to precompile your assets.John Beynon
That is correct, but that wasn't the pre-compilation option I was looking for. This solution is to be used for wanting to compile assets at slug compilation time specifically.Tyler Brock

2 Answers

18
votes

Ok so the solution was this:

I'm using mongoid which has you remove the 'rails/all' line as part of the configuration. As a result sprockets was not being loaded.

What you need to do with rails 3.1+ is also add require "sprockets/railtie" in application.rb so that sprockets are enabled. Boom, works.

This info can be found on the mongoid website here. This is useful to know for anyone who may not be loading the full 'rails/all' in application.rb, sprockets is obviously required for the asset pipeline to work.

2
votes

Have you seen this article on Rails 3.1 asset pipeline on Heroku - http://devcenter.heroku.com/articles/rails31_heroku_cedar. I reviewed it yesterday and picked up a good few hints from it and I've been running Rails 3.1 sites on Heroku for quite a while now.

Was this a new Rails 3.1 site or a site upgraded to Rails 3.1, things to check would be that the asset pipeline is enabled for production - by default Rails 3.1 uses

config.assets.enabled = false

in application.rb. Are you using app/assets for your assets and not public/