Search code examples
ruby-on-railstwitter-bootstrap-3passengerglyphiconsbootstrap-sass

Rails + Bootstrap: Font path not including base URI (production)


I'm using the bootstrap-sass gem and in production my rails app is deployed under a subfolder, i.e. the root is http://www.example.com/sub/. Everything works fine except for the fonts (particularly, Glyphicons): in the CSS the path to the font is this:

url("/assets/bootstrap/glyphicons...

when it should be

url("/sub/assets/bootstrap/glyphicons...

The CSS and JS assets all have the correct path, but the fonts don't. I've looked around the documentation (and the rest of the web) for a while but can't find how to change this--I'm a noob when it comes to the asset pipeline stuff.

I've got it deployed on Linux-Apache-Passenger.

Edit: I should add that I have this in my Apache site config:

Alias /sub /path/to/rails/app/public
<Location /sub>
    PassengerBaseURI /sub
    PassengerAppRoot /path/to/rails/app
</Location>
<Directory /path/to/rails/app/public>
    Allow from all
    Options -MultiViews
</Directory>

Solution

  • Here was the config option I needed in config/application.rb:

    config.action_controller.relative_url_root = '/sub'
    

    I would guess it's because the Apache/Passenger directive doesn't take effect when precompiling assets (e.g. the Bootstrap SASS) so you need to let the precompiler know where the fonts will be. Thanks for the help, wkaha and archie, and here's the ilnk on the bootstrap-sass github that clued me in: https://github.com/thomas-mcdonald/bootstrap-sass/issues/443