1

I am trying to use bootstrap for my RubyonRails application and I am not able to set it up.

In my Gemfile I added

#Bootstrap
gem 'bootstrap-sass', '3.3.5'
gem 'autoprefixer-rails'

I did bundle install after that

I created a application.css.scss in the app/assets/stylesheets folder and the contents are:

/*
 * This is a manifest file that'll be compiled into application.css, which will include all the files
 * listed below.
 *
 * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
 * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
 *
 * You're free to add application-wide styles to this file and they'll appear at the bottom of the
 * compiled file so the styles you add here take precedence over styles defined in any styles
 * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
 * file per style scope.
 *
 *= require_tree
 *= require_self
 */
@import "bootstrap-sprockets";
@import "bootstrap"

app/assets/javascripts/application.js :

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap-sprockets
//= require_tree .

When I run the rails server and go to my root page, I get the following error:

couldn't find file 'bootstrap' with type 'text/css'
6
  • 2
    can you check to see what version of 'sprockets' you have? Run bundle list | grep sprockets Commented Sep 11, 2015 at 22:39
  • @nzajt sprockets (3.3.4) * sprockets-rails (2.3.3) Commented Sep 11, 2015 at 22:40
  • that isn't the issue. From the github page "Please make sure sprockets-rails is at least v2.1.4." and you do. Commented Sep 11, 2015 at 22:41
  • Sorry, I think that issue is that you need the application.css to be application.scss Commented Sep 11, 2015 at 22:43
  • Right now it is application.css.scss. Should there be css? Commented Sep 11, 2015 at 22:43

2 Answers 2

3

Take your application.css and turn it into application.scss. There should not be any thing above this in your file. Remove all the old code above. It should just be.

@import "bootstrap-sprockets";
@import "bootstrap";

If you want to add another file you just add it below. like

@import "bootstrap-sprockets";
@import "bootstrap";
@import "ANOTHER SCSS FILE";
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks its working now :) Will I need to include anything in my application.html.erb file? Are all the bootstrap fonts/javascript files loaded?
You should be good. As long as you keep the name application.scss you should be good.
0

Had the same issue, the only thing that helping was including the older version of the SASS gem

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

Use SCSS for stylesheets

gem 'sass-rails', '~> 5.0'

2 Comments

Had the same issue , after spending an hour on the stackoverflow/github, found that the only solution was to: add the gem 'saas-rails' '>3.2' and comment out the gem 'sass-rails''~5.0'
i had the same issue :couldn't find file 'bootstrap-sprockets' with type 'application/javascript' The only solution was to comment off gem 'sass-rails', '~> 5.0' and add instead gem 'sass-rails', '>= 3.2' in the Gemfile, hope this helps other members

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.