Search code examples
ruby-on-railsrubytwitter-bootstrap-3

Installing Bootstrap 3 on Rails App


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?


Solution

  • 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.

    Update: According to many comments asking why we need 2 files min and non-min. Answer: you absolutely don't need both files. But it is good to have both files just for reference. In case you need to see the source for debugging for example. Otherwise, just include a single source file, which should be compressed and minified by sprockets. But be aware that it might not be minified in the best way as the original file.