Riptyde4
Riptyde4

Reputation: 5460

Rails 4 app not including bootstrap css in assets?

I've followed the instruction in this answer to install bootstrap on my Rails 4 app: https://stackoverflow.com/a/20661571/2247192 (substituting Bootstrap 3.3.6 for the version referenced in this answer)

I was previously using the CDN version, it was working fine but I was having issues with dropdown menus and that seems to be an issue that has come up before using the CDN so I figured i'd give this a shot.

Now, I'm getting completely unstyled pages as if there is no CSS for bootstrap at all.

app/assets/stylesheets/application.css:

*= require bootstrap.min

body {
    padding-top: 50px;
    overflow: hidden;
}

app/assets/javascripts/application.js:

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

Do I have to change anything in my application.html.erb besides removing the <script></script> tags for the css online?? Add any <link rel=...> tags?

Upvotes: 0

Views: 215

Answers (2)

Richard Peck
Richard Peck

Reputation: 76774

To add to @Grammakov's answer, there is a much better way; using Rails Assets:

#Gemfile
source 'https://rubygems.org'
source 'https://rails-assets.org'

gem 'rails-assets-tether' #-> bootstrap 4 requires
gem 'rails-assets-bootstrap', ">= 4.0.0.alpha"

The beauty of this technique is that it actually pulls from the bootstrap repo, rather than relying on a third-party gem.

To integrate into your app, you'll have to use the following:

#app/assets/javascripts/application.js
//= require tether
//= require bootstrap

#app/assets/stylesheets/application.css
/*
  *= require bootstrap
*/

Upvotes: 1

The Whiz of Oz
The Whiz of Oz

Reputation: 7043

Try requiring bootstrap instead of bootstrap.min in both js and css manifest files

Try installing bootstrap as a gem

gem 'bootstrap-sass', '~> 3.3.6'
gem 'sass-rails', '>= 3.2'

and follow instructions here

Upvotes: 1

Related Questions