Search code examples
cssruby-on-railstwitter-bootstrapruby-on-rails-2

Installing twitter bootstrap with Rails


I am trying to install on an existing project Twitter Bootstrap

I tried to do that, following this :

group :assets do
  gem 'bootstrap-sass-rails'
end

and I got that :

Bundler could not find compatible versions for gem "actionpack":
  In Gemfile:
    bootstrap-sass-rails (>= 0) java depends on
      actionpack (~> 3.1.0) java

    rails (= 2.3.14) java depends on
      actionpack (2.3.14)

Bundler could not find compatible versions for gem "rails":
  In Gemfile:
    bootstrap-sass-rails (>= 0) java depends on
      rails (~> 3.1.3) java

    rails (2.3.14)

Knowing that when I run rails -v, I get rails 3.2.12. So, following the doc, I tried this

gem install bootstrap-sass-rails

I am told that the gem is successfully installed but I don't see any new file in my app folder. By the way, I tried to add in one of my stylesheet this

**/*
 *= require twitter/bootstrap
 */
**

But no bootstrap css seems to be called on my layouts. Could someone help ? Is this the right way to install Bootstrap ?

update : I have just noticed that in the gem file I have : gem "rails", "2.3.14"


Solution

  • For Rails 3:

    I have bootstrap and fontawesome installed. Here's my Gemfile:

    source 'https://rubygems.org'
    
    gem 'rails', '3.2.12'
    
    # ...
    
    # jQuery
    gem 'jquery-rails'
    
    # Twitter Bootstrap
    gem 'bootstrap-sass'
    gem 'font-awesome-sass-rails'
    
    # Gems used only for assets and not required
    # in production environments by default.
    group :assets do
      gem 'sass-rails'
    end
    

    As you can see, I use a different gem for bootstrap. After editing Gemfile, just type bundle (or maybe bundle update is necessary)


    This is my application.css.scss (under app/assets/stylesheets/):

    @import "bootstrap";
    @import "font-awesome";
    body { padding-top: 60px; }
    @import "bootstrap-responsive";
    

    And application.js (under app/assets/javascripts/):

    //= require jquery
    //= require jquery_ujs
    //= require bootstrap
    //= require_tree .