MARUGOSHI.ORG

twitter-bootstrap without gem

I know of a gem to use twitter-bootstrap with Rails, but I don’t like such solutions because of dependency. If I use it then twitter-bootstrap upgrade it’s versions, I will have to wait gem to catch up those upgrades. Even github helps us to collaborate really straightforward, but sometimes two steps solutions make problems more complicated.

This is a memorandum to use twitter-bootstrap with Rails WITHOUT any gems. I don’t know it’s a right way but it’s well enough for me.

Download and place files under “vendor”

After creating a new rails project, download twitter-bootstrap, then place files under vendor directory.

#{Rails.root}/vendor/assets/javascripts/twitter-bootstrap/bootstrap.min.js

#{Rails.root}/vendor/assets/stylesheets/twitter-bootstrap/bootstrap.min.css

Place images under “assets/images”

Image files must be place under directory where browser can access.

#{Rails.root}/assets/images/twitter-bootstrap/glyphicons-halflings-white.png

#{Rails.root}/assets/images/twitter-bootstrap/glyphicons-halflings.png

Create vendor.js and vendor.css

I don’t know how to edit application.js and application.css to load whole files under vendor directory, so I create files for that.

# cd #{Rails.root}

$ cat app/javascripts/application.js
//= require vendor

$ cat app/stylesheets/application.css
/*
 *= require vendor
 */

$ cat vendor/javascripts/vendor.js
//= require ./twitter-bootstrap/bootstrap.min

$ cat vendor/stylesheets/vendor.css
/*
 *= require_tree ./twitter-bootstrap
 */

Edit file - BAD SOLUTION

Overriding selectors is the only one answer, but I edited twitter-bootstrap.min.css directly to replace image file paths. it’s a very bad solution but I gave up to be a smart.