Read more

bower-rails can rewrite your relative asset paths

Henning Koch
November 03, 2014Software engineer at makandra GmbH

The asset pipeline changes the paths of CSS files during precompilation. This opens a world of pain when CSS files reference images (like jQuery UI) or fonts (like webfont kits from Font Squirrel), since all those url(images/icon.png) will now point to a broken path.

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

In the past we have been using the vendor/asset-libs folder as a good solution to work around this.

When you migrate to managing vendor assets in Rails with Bower, the bower-rails gem comes with its own solution for this problem. It can rewrite your .css files so all occurences of url(...) are replaced by something like url(<%= asset_path(...) %>) in a .css.erb file ( code Show archive.org snapshot ).

You can do this manually by invoking a Rake task:

rake bower:resolve

... or you can configure your application to automatically resolve paths before precompiling assets:

BowerRails.configure do |bower_rails|
  # Invokes rake bower:resolve before precompilation. Defaults to false
  bower_rails.resolve_before_precompile = true
end
Posted by Henning Koch to makandra dev (2014-11-03 10:09)