CSS is looking different on heroku

前端 未结 5 1741
一整个雨季
一整个雨季 2020-12-29 09:27

As you should see in the images below, the css on my local host site is spaced much better at the top than it is on heroku.

Has anyone had this type of problem bef

相关标签:
5条回答
  • 2020-12-29 09:54

    The problem is related to the handling of the asset pipeline on Heroku. There are several ways on how this can be handled, see http://devcenter.heroku.com/articles/rails31_heroku_cedar

    I fixed the issue in my application by pre-compiling the assets locally on my machine and then pushing them to Heroku.

    Pre-compile the assets:

    RAILS_ENV=production bundle exec rake assets:precompile
    

    Add/commit the changes to git repository:

    git add public/assets
    git commit -m "vendor compiled assets"
    

    To be safe I tested the whole thing on a local branch on my machine first which I pushed to Heroku using the following command (Heroku normally ignores all branches except the master branch, thus the trick):

    git push -f heroku heroku-assetpipeline:master
    
    0 讨论(0)
  • 2020-12-29 10:00

    Is it possible that you pre-compiled your assets locally at some point? To force heroku to compile your assets during slug compilation you can rename your public/assets/manifest.yml to public/assets/manifest.yml.bak, commit your source, and push to heroku.

    Heroku assumes you compiled your assets locally when it sees the manifest.yml file.

    0 讨论(0)
  • 2020-12-29 10:06

    I had this same problem and followed the instructions of a couple of different pages including Heroku's own documentation. I'm posting here to help the next guy because possibly due to changes in Rails 4, Heroku, or Github but the above directions did not work at all for me. However I did get it to work and here's how.

    Yes you probably should precompile your assets using RAILS_ENV=production bundle exec rake assets:precompile but after that go into you 'public/assets' folder and copy "all" '.css','css.gz', '.json', '.yml', '.js' files that start either with 'application' or 'manifest'. Move them to a folder outside of the application's directories. Do this just encase anything goes wrong. Verify all of those files are deleted from the apps 'public/assets/' folder. Next restart your local rails server and verify your app is still behaving as you intend it to. Then go to your Github account and go into the 'public/assets/' directory of your repository and delete all the same files that you just did locally. Then add/commit locally, then push to git, then to heroku, and walla you're done it should be working.

    The rationale behind it, what I assume, is because when you push to Heroku it checks for compiled assets in your repository and because of this, even though I had precompiled locally, it was still pulling some asset configurations from previous commits. By removing these files, Heroku must compile them during the push. One thing I didn't try which may work is just switching to another branch and deleting those files and deploying that branch to Heroku, so you may want to try that first, but this is what worked for me.

    One other note, renaming the files to .bak or .old Heroku still considered them as their regulars and displayed them as it was the original ones that were not displaying properly.

    0 讨论(0)
  • 2020-12-29 10:07

    FWIW, I had this same issue and checked everything I could think of, as well as those above. It turned out I must have zoomed out in my browser while on localhost, and I had the standard zoom on my production url.

    It was as simple as resetting the zoom in my browser on both pages. Hope this helps someone else with the same problem.

    0 讨论(0)
  • 2020-12-29 10:15

    I have the very same issue. When I compare the development and production code, it occurs that on the development machine the stylesheets and javascript files from bootstrap all get loaded whereby on the production site (Heroku), there is only one application-XYZ.css and one application-XYZ.js.

    I am not sure if this could be an issue with the asset pipeline.

    Could probably someone elaborate on what needs to be done to (pre-)compile the asset pipeline such that deployment on Heroku succeeds.

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