Question

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>
Was it helpful?

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

OTHER TIPS

does this helps?

http://guides.rubyonrails.org/asset_pipeline.html

2.3.1 CSS and ERB

The asset pipeline automatically evaluates ERB. This means that if you add an erb extension to a CSS asset (for example, application.css.erb), then helpers like asset_path are available in your CSS rules:

.class { background-image: url(<%= asset_path 'image.png' %>) }

This might be the reason.

Bootstrap-sass gem precompiles the glyphicons

config.assets.precompile << %r(bootstrap/glyphicons-halflings-regular.(?:eot|svg|ttf|woff)$)

Suggested workaround:

Copy the 4 glyphicon files into your assets pipeline and precompile in your own production or development config.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top