Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Most of my assets suddenly return 404 after a push to heroku

I have deployed this app (rails 3.2.11) a million times, I haven't messed with any settings, but now I'm greeted with this:

enter image description here

Why did this happen out of the blue? My conents of application.rb include config.assets.enabled = true - never had any issues.

In fact running it locally on port 3000 seems to not have any issues whatsoever.

After deploying to heroku this morning, it seems that it loads nothing that's inside /assets/

Interestingly, after copying the files over to try and just make a new app, git commit results in all the stuff you'd expect as well as a LONG list of these which I think might be related:

enter image description here

Edit: Interestingly enough SOME of the assets have loaded, like the logo and the background, but the rest as you can see return 404.

like image 932
dsp_099 Avatar asked May 21 '13 12:05

dsp_099


4 Answers

put line in config/environments/production.rb

config.assets.compile = true

it worked as it will compile the assets on runtime, just like in development environment, but its makes application slow, the best way is to either compile the assets locally in production environment with rake task(RAILS_ENV=production bundle exec rake assets:precompile) and commit your generated assets in public/assets and then do deployment. or, heroku run rake assets:precompile

like image 101
Sachin Singh Avatar answered Nov 11 '22 00:11

Sachin Singh


I had this problem today with rails 4 on heroku. The article provided by @Jeff is a little bit old but, the gem repository has a good readme. Summarizing, you will need to add two gems to your Gemfile:

  1. gem 'rails_serve_static_assets' (it will solve the static assets problem) and
  2. gem 'rails_stdout_logging' (which the previous one depends on).
like image 41
Alfredo Cavalcanti Avatar answered Nov 11 '22 00:11

Alfredo Cavalcanti


Heroku released a gem to handle the assets without needing to turn off compilation or to manually compile.

https://devcenter.heroku.com/articles/ruby-support#static-assets

Just add this to your Gemfile and redeploy.

gem 'rails_serve_static_assets', group: [:production]
like image 7
Jeff Avatar answered Nov 11 '22 00:11

Jeff


For Rails 4, use:

config.serve_static_assets = true

The default was false. We needed this after removing the rails_12factor gem.

like image 3
B Seven Avatar answered Nov 11 '22 02:11

B Seven