Search code examples
ruby-on-railstwitter-bootstrapbootstrap-sass

Rails: Bootstrap glyphicons not loading in production


After upgrading to Rails 5, the Bootstrap glyphicon icons are not loading properly on heroku. For instance, the Trashcan icon is showing up as a question mark. It appears that the browser is not finding the glyphicon asset and loading its own interpretation. I am using bootstrap-sass 3.3.7.

When the glyphicons are loaded, if I open the console, I see errors like this:

A server with the specified hostname could not be found
https://assets/bootstrap/glyphicons-halflings-regular-fe185d11a49676890d47bb783312a0cda5a44c4039214094e7957b4c040ef11c.woff2

It looks to me that the asset host is not being set properly for the bootstrap assets. In my production.rb file, I have the line

config.asset_host = "https://#{ENV['RAILS_HOST_PATH']}"

and if I do heroku config --remote production, the value of RAILS_HOST_PATH is www.example.com.

If I look at Rails.application.config.asset_host it does correctly show "https://www.example.com". However it looks like for the bootstrap assets, the domain is resolved as https://.

What is going on here?


Solution

  • Further investigation revealed that it was not a problem with Rails 5 per se, but due to changing the production.rb file in upgrade, and following Heroku's advice on using ENV variables for such files.

    Accordingly, I needed to specify the target RAILS_HOST_PATH in the precompilation i.e. RAILS_ENV=production RAILS_HOST_PATH=www.example.com rake assets:precompile