Glyphicon works locally but not on Heroku

后端 未结 6 934

If you look at my app here: http://quiet-brushlands-5712.herokuapp.com/, close to the button is an icon, a glyphicon. But it\'s not appearing on heroku. locally it show as nicel

相关标签:
6条回答
  • 2021-02-04 08:41

    In config/environments/production.rb

    Change config.assets.compile = false to config.assets.compile = true

    (and then don't forget to commit and push to heroku)

    Worked for me...

    0 讨论(0)
  • 2021-02-04 08:43

    The solution was to change config.assets.compile = false to config.assets.compile = true in the config/environments/production.rb file.

    0 讨论(0)
  • 2021-02-04 08:46

    Because I came to this answer when I was searching I figure I should put here that the solution I came across was to include an import to "bootstrap-sprockets" before bootstrap. This is documented at https://github.com/twbs/bootstrap-sass/issues/653.

    I realize the question isn't using bootstrap-sass 3.2+ but I figure this may help someone.

    0 讨论(0)
  • 2021-02-04 08:59

    Further to Vidya's comment, it's probably going to be your asset pipeline that's the problem

    Although I'm not familiar with the specifics of Bootstrap for this, there is a major issue with Heroku's asset pipeline, being that it has to be precompiled before you can use it effectively


    Asset Fingerprinting

    Heroku requires you to precompile your assets because of asset fingerprinting

    This is where your assets will have a hash applied to the end of their filename, like image-12sdafdsafkj223423jnjfadsnfsad.png or similar. The reason for this is apparently to keep the assets unique or something

    If you follow the link provided by Vidya, you'll find that Heroku prompts to you precompile your assets using the Rails CMD. What it doesn't tell you is that this will mess up your images unless they've been dynamically-assigned


    SCSS

    As mentioned, I'm not sure about how this applies to Bootstrap specifically, but with Heroku's asset pipeline stuff, you need to ensure your images are assigned using dynamic paths

    Like in Rails itself, SCSS allows you to use asset_path or image_path to create a dynamic link. This is what you have to do to fix your problem. Here's some code we use, which works on Heroku:

    .navigation_bar {
            z-index: 200;
            position: relative;
            background: asset_url('nav_bar/bg.png') repeat-x top;
    }
    
    0 讨论(0)
  • 2021-02-04 09:02

    Solution that not use the compilation fallback (tested on Rails 4.1): In your scss files, import bootstrap-sprockets just before bootstrap.

    @import "bootstrap-sprockets";
    @import "bootstrap";
    
    0 讨论(0)
  • 2021-02-04 09:02

    If you do not want to set your config.assets.compile to true in your production environment (which you probably shouldn't for better performance), you can manually precompile your assets before you push to heroku using rake assets:precompile RAILS_ENV=production

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