Today I learned

Using Bower and Rails in Heroku

Update (Jan 2019): Bower hasn't been maintained for years, and using Bower packages should now be considered a discouraged practice.

This seems pretty easy until you realize that Bower (a Node.js package) is not available in the Heroku Ruby build pack. The gem bower-rails allows for easy Bower integration into Rails, but it won't work out of the box in Heroku.

Solution: add execjs

The Ruby buildpack has a magic behavior where if it detects the execjs gem, it will bundle Node.js with the build. This should make it work.

gem 'execjs'

Alternative solution

Use the Multi buildpack to combine Ruby and Node buildpacks.

heroku config:add BUILDPACK_URL=https://github.com/ddollar/heroku-buildpack-multi.git
# vim .buildpacks
https://github.com/heroku/heroku-buildpack-nodejs.git#v60
https://github.com/heroku/heroku-buildpack-ruby.git#v127

I recommend locking the versions (#v60) to ensure that you get versions that interoperate together (in case one upgrades and breaks interoperability).

The last pack defined (Ruby in this case) is the "main" one that defines the process types (web, console, etc).

You have just read Using Bower and Rails in Heroku, written on February 24, 2015. This is Today I Learned, a collection of random tidbits I've learned through my day-to-day web development work. I'm Rico Sta. Cruz, @rstacruz on GitHub (and Twitter!).

← More articles