Better Asset Management in Rails Using Rails Assets
Bower is a package manager for such assets, and would have solved this problem. But I was reluctant to add another package manager to the mix and make the deployment setup even more complex.
That’s when I came across rails-assets, which is a proxy between bundler and bower. This allows us to include bower packages in our application using only bundler. You don’t need to have bower installed on your machine.
To use it, you need to add
source 'https://rails-assets.org' at the top of your Gemfile, and then include any bower packages as gems with
rails-assets- prefixed to their name.
For example, you could add
gem 'rails-assets-bootstrap' and you will be able to accesss bootstrap assets from application.js (using
//= require bootstrap) and application.css (using
*= require bootstrap).
When you request a gem from rails-assets, it converts bower packages into gems that can be installed via bundler. I’ve only used it with Rails, but it is compatible with any sprockets based application.
The project has been around for more than a year, and it seems to be stable. Although I haven’t yet moved to rails-assets for all the client side assets in my app, this has already simplified the asset dependencies a great deal.