One of the beauties of the Ruby ecosystem is the vast number of gems that are available for us as developers, all we have to do is to gem install or add the gem we want to use in our Ruby on Rails app, run bundle install, and voilá, that gem is ready for use. The magic doesn’t end there though, as there is a lot of work and logic happening behind the scenes every time we run those commands. One of them is something called Dependency Management, and the idea it’s pretty simple: “If gem A depends on gem B and B depends on C, then when I request A, go fetch B and go fetch C”.
Rails-assets.org is new solution to assets management in Rails. The idea is to follow the steps of rubygems.org, but goes a step further (as described on their website): “It automatically coverts the packaged components into the gem that are easily droppable into your asset pipeline and stay up to date”. This is how it works:
- First you include: source 'https://rails-assets.org' in your gemfile
- Then call the bower package you want to include in your project: gem 'rails-assets-BOWER_PACKAGE_NAME’
- Inside you application.js and .css, require those .js and .css files needed based on your library install instructions
- Run bundle install
After that, your library is installed as a gem and you are off to the races. Behind the scenes, rails-assets.org will fetch the component from Bower’s registry, then analyze its bower.json file and repackage the component as a valid gem. All dependencies are handled for you. It’s a pretty clever way to use the latest version of a given library.
Rails-assets.org is a new project and still maturing. Like anything, it has its pros and cons (like you can’t specify a given package version like we can using rubygems.org), but with time it could become one of our best tools in our Ruby belt.