user1692342
user1692342

Reputation: 5237

Using bootstrap in Ruby on rails Error

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'

Upvotes: 1

Views: 479

Answers (2)

tzurcan
tzurcan

Reputation: 11

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'

Upvotes: 0

nzajt
nzajt

Reputation: 1985

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";

Upvotes: 3

Related Questions