Rails 4 images not loading on heroku

后端 未结 9 1608
一个人的身影
一个人的身影 2020-11-28 01:40

I have spent the better part of the day trying to get images to load on my heroku app. Everything I try works locally, but not after being deployed to heroku.

I h

相关标签:
9条回答
  • 2020-11-28 02:22

    The images won't be served as assets by default, only css and js. You should look into the answer of

    Syed Ehtsham Abbas in this question Heroku does NOT compile files under assets pipelines in Rails 4

    0 讨论(0)
  • 2020-11-28 02:27

    You need to do two things to resolve it. First, change these two lines from false to true in production.rb file.

          config.assets.compile = true
          config.assets.digest = true
    

    Second, if you've syntax like this for your images

        background: url("imgo.jpg") 
    

    Change it to

         background: image-url("image.jpg")
    

    I hope it does your job.

    0 讨论(0)
  • 2020-11-28 02:30

    Another issue, I was having with this was that I was precompiling my assets locally, prior to loading it to heroku. This requires you to follow a different set of steps, which can be found below. If you precompile your assets locally, you must follow these steps or any updates you made to your assets folder will not be reflected in prod.

    https://devcenter.heroku.com/articles/rails-asset-pipeline

    RAILS_ENV=production bundle exec rake assets:precompile

    commit and push to server.

    0 讨论(0)
提交回复
热议问题