Installing Bootstrap 3 on Rails App

megashigger picture megashigger · Aug 22, 2013 · Viewed 101.9k times · Source

I'm trying to install Bootstrap 3.0 on my Rails app. I recently finished Michael Hartl's tutorial and am now trying to build my own system using this new version of Bootstrap, but I have a few questions that I'm not sure about.

My system specs:

  • OS X Mountain Lion on MBP
  • Rails 4.0
  • Ruby 2.0

Questions I have:

  1. What is the best gem to use in my Gemfile? I have found a few of them.
  2. What do I import on my custom.css.scss? I read somewhere that it's different from 2.3.2.
  3. Is there anything else I have to do to get Bootstrap to work, or are the remaining steps identical to the ones I followed for Bootstrap 2.3.2?

Edit

Here is what the bootstrap-rails project on GitHub first says to do:

gem 'anjlab-bootstrap-rails', :require => 'bootstrap-rails',
                              :github => 'anjlab/bootstrap-rails'

Then it says to do:

gem 'anjlab-bootstrap-rails', '>= 3.0.0.0', :require => 'bootstrap-rails'

Do they do the same thing, or do you have to do them both?

Answer

hawk picture hawk · Aug 22, 2013

Actually you don't need gem for this, here is the step to install Bootstrap 3 in RoR

  • Download Bootstrap

  • Copy:

    bootstrap-dist/css/bootstrap.css and bootstrap-dist/css/bootstrap.min.css

    To: vendor/assets/stylesheets

  • Copy:

    bootstrap-dist/js/bootstrap.js and bootstrap-dist/js/bootstrap.min.js

    To: vendor/assets/javascripts

  • Update: app/assets/stylesheets/application.css by adding:

    *= require bootstrap.min
    
  • Update: app/assets/javascripts/application.jsby adding:

    //= require bootstrap.min
    

With this you can update bootstrap any time you want, don't need to wait gem to be updated. Also with this approach assets pipeline will use minified versions in production.