user5164376
user5164376

Reputation:

Can't get Bootstrap template working on rails/sass

I have been trying to install a template from getboostrap website onto my rails app.

I can get all the templates to work from the section 'using the framework' but when I try to use the 'custom components' themes they won't load properly - its like the css file is missing or something.

This is how I linked the css files (inside index.html.erb)

I replaced . . .

<!-- Bootstrap core CSS -->
<link href="../../dist/css/bootstrap.min.css" rel="stylesheet">

<!-- Custom styles for this template -->
<link href="cover.css" rel="stylesheet">

With . . .

<!-- Bootstrap core CSS -->
<link href="../../assets/stylesheets/bootstrap.min.css.scss" rel="stylesheet">

<!-- Custom styles for this template -->
<link href="../../assets/stylesheets/cover.css.scss" rel="stylesheet">

Any additional things I need to do? Thanks!

Upvotes: 0

Views: 292

Answers (2)

adamliesko
adamliesko

Reputation: 1915

Read the instructions of the bootstrap-sass gem and follow their conventions https://github.com/twbs/bootstrap-sass.

In your Gemfile add

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

Into application.scss

Import Bootstrap styles in app/assets/stylesheets/application.scss:

// "bootstrap-sprockets" must be imported before "bootstrap" and "bootstrap/variables"
@import "bootstrap-sprockets";
@import "bootstrap";

Ensure that application.html.erb has this line inside

<%= stylesheet_link_tag 'application', media: 'all' %>

Upvotes: 1

Stefan
Stefan

Reputation: 3041

You need to use the Rails helpers for including SCSS since the SCSS needs to be precompiled.

In your layout.html.erb there should be <%= stylesheet_link_tag 'application', media: 'all' %> if not add it.

At the top of app/assets/stylesheets/application.css.scss add: /* *= require bootstrap.min.css */

Upvotes: 0

Related Questions