Jayson Lane
Jayson Lane

Reputation: 2828

Heroku Assets Precompile

Today I was working with an application I've had running on Heroku for a few months now and in an attempt to get something working I ran in my development environment:

rake assets:precompile

When I committed my changes and pushed to Heroku, I get 500 errors on my request:

ActionView::Template::Error (jquery.flexslider-min.js isn't precompiled):

I'm at a bit of a loss as to what to do, I've tried a few things:

Lazily compile in production (which I really don't want to do):

Bundler.require(:default, :assets, Rails.env)

Specifically list all of the files that need to be "precompiled" (also don't really want to do this, doesn't seem very efficient):

config.assets.precompile += ...

So far I've simply done a rollback to my last working version. I'm currently stuck unable to push new code. Will be setting up a staging environment (like I should've done long ago) but not sure what to do next or what might fix this issue? Why didn't this throw an error before?

UPDATE

rake assets:clean

Appears to have resolved the problem, although I don't understand why. Can someone share some insight into this?

Upvotes: 2

Views: 8113

Answers (3)

Sebastian
Sebastian

Reputation: 2204

Found the solution in the GitHub thread:

increment the config.assets.version variable in ${project-root}/config/application.rb

Assets were refreshed after I'd added config.assets.version = '1.1' at the end of my config file.

Upvotes: 1

thank_you
thank_you

Reputation: 11107

If you running Rails 4.0 or above, rake assets:clean has been replaced with rake assets:clobber.

However, there are some current problems with clean and clobber with regards to permanently deleting assets. You can follow the issue here. https://github.com/heroku/heroku-buildpack-ruby/issues/123

Upvotes: 3

JamesDullaghan
JamesDullaghan

Reputation: 1340

I'm willing to bet a compiled version/filename inside of manifest.yml in the public/assets folder was out of date/wrong.

If you've made changes to the flexslider.js file, you'll need to recompile with rake assets:precompile and push the updated version to github. I believe you can set the version of the assets inside of the manifest.yml file.

Also, I believe you can run heroku run rake assets:clean or heroku run rake assets:precompile.

I don't think it would be a good idea to precompile assets inside of heroku because of versioning and name conflicts/not stored in github.

You can clean the assets in heroku and push the repo again, so you wouldn't need to precompile locally and push to github, unless there was indeed an issue in the local compilation.

I'd also take a few minutes to read http://guides.rubyonrails.org/asset_pipeline.html

Another possibility is your file name is having issues with sprockets. Why not use the development version of the flexslider.js, rename it to something slightly more convenient, and allow sprockets to do the minification.

Upvotes: 2

Related Questions