Spectacular Assets

With Bower And Cloud66

Braden Douglass
2 min readJun 3, 2014

Application asset management has exploded in the last few years with a myriad of options. No longer is sprockets the only player in the game. However, actually finding time in a busy day can block us from experimenting with these new tools. Starting green-field applications can be fun and great way to learn some of these new pieces of technology. Having just started a fresh Rails 4 app, we decided, to give Bower a whirl for our asset management. To start, we simply created the traditional bower.json and bower.rc files and described each one of our dependencies. If this is the first time hearing about the power of Bower, this is what 90% of the web recommends when getting started.

For the remainder of the app’s first 15 seconds of development, this workflow went well. Find a specific Bower package you wanted to incorporate? Add it to the bower.json file, call it in the sprockets manifest and BOOM! Life was grand. However, everything took a steep decline when we decided to push these changes to our staging server managed by the fine folks at Cloud66.

At first, we decided to build a special “before hook” where Cloud66 would run the required npm install and bower install during the code deployment process. This process never took place. We moved the hook between before_rails, after_rails, before_bundler, and etc. All with no luck whatsoever. This isn’t to say that Cloud66’s deploy hook system isn’t great, because it certainly has its use cases.

Having failed several times in a row and like good Rubyists, we looked for other solutions that would allow us to enjoy the power of Bower with Cloud66. It just so happens that the wonderful guys and gals atMontrail had established a solution called: rails assets.

Reminiscent to gems, Bower assets are no longer defined in a separate separate .json file. Instead, they get lumped into the well known Gemfile. By adding this source declaration at the top of the Gemfile, you can then add whatever bower package you want to the bottom of the Gemfile (or wherever you define your asset based gems).

source ‘https://rails-assets.org'

view rawGemfile.rb hosted with ❤ by GitHub

From here, we simply required the specific package in theapplication.js or application.css and BOOM! No longer did we receive an error on bundle due to not being able to find a specific directory that had yet to be created during the deploy process.

From what we have seen, this creates a very seamless integration utilizing Bower in Development and Production environments. With little effort you will have up-to-date assets and an efficient, well-known, way to update and install more packages in the future.

--

--

Braden Douglass

Chaotician on a bender to modernize the Minitel UX/UI. Currently striving to make Ruby based ecommerce a ‘better’ place.