Glyphicon works locally but not on Heroku

Deadly 提交于 2019-12-02 23:10:57
Emmanuel

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

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";

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;
}

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

iGaape

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...

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!