hikmatyar
hikmatyar

Reputation: 507

Heroku app not loading pictures properly

I'm having issues loading up pictures on my Heroku app.

It's driving me nuts.

I have a page with 5 pics on it. It loads up perfectly fine on my local host, but when I try opening up the app on Heroku, only 2 of the 5 images load correctly.

For the rest, I get a 404 error saying RoutingError. I've checked my code over and over again; checked that the files are in public/assets; checked that the file names are being properly referenced in both places but still getting this error.

What could be the problem????

Thanks,

Faisal

Upvotes: 2

Views: 2520

Answers (3)

przbadu
przbadu

Reputation: 6049

Enable assets precompile for production server

config/environments/production.rb

config.serve_static_assets = true
config.assets.compile = true

push your changes to both github and heroku

git add .
git commit -m "Enable assets precompile for production environment"
git push origin master

git push heroku master

That's it :)

Upvotes: 0

hikmatyar
hikmatyar

Reputation: 507

Alright, I figured it out. I deleted the pics from public/assets, committed the code, then added the pics back and committed again, and pushed the code.

Note: actually found this fix 2 mins after posting the question, but SO wouldn't let me post the answer until now.

Upvotes: 1

Dru
Dru

Reputation: 9820

If you do not precompile your assets before deployment I would try this(or a variation of it):

bundle exec rake assets:precompile
git add . 
git commit -m "precompiled assets"
git push heroku master

Upvotes: 1

Related Questions