2

I am installing the bootstrap-sass gem and I need to import Bootstrap into application.css.scss like:

@import "bootstrap";

however I can't find it in my assets/stylesheets folder. Do I just create it? Will my Rails app load this file?

I do have installed sass-rails:

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

I placed this in my styles.css.scss:

@import 'bootstrap';
@import 'bootstrap/responsive';

Gemfile:

group :assets do
  gem 'bootstrap-sass', '~> 2.3.2.0'
end

Any help is greatly appreciated.

  • Make sure you dont have application.css (not: no .scss extension) and then create application.css.scss. If you add `@import` statement, it should work. Try out and post back if you get any errors. – Anirudhan J Dec 29 '13 at 16:58
  • @AnirudhanJ I get this error: "File to import not found or unreadable: bootstrap." I did install the gem. Do I have to do anything else after that? –  Dec 29 '13 at 17:06
  • 1
    Okay. That means your application.css.scss is getting read. If you are in rails 3 declaring a gem within assets group will make the gem available only in development environment. Refer http://stackoverflow.com/a/7675331/846970. Might that be a problem for you? If not can you provide more information? – Anirudhan J Dec 29 '13 at 17:16
  • OK. Without question that would be something I wouldn't find out on my own. Thanks a million @AnirudhanJ! –  Dec 29 '13 at 17:22
  • So it worked? The issues was in Gemfile? – Anirudhan J Dec 29 '13 at 17:27
  • The issue was with the assets not being available in development envirnment. I did what the guy suggested in the link you send me. Cheers! –  Dec 29 '13 at 17:31
  • Great. Will add this as answer just in case someone has the same issue and ignores SO comments. – Anirudhan J Dec 29 '13 at 17:34

2 Answers2

3

Reposting my answer from comments.

application.css.scss is not present by default in rails app even though sass-rails is included. You can remove application.css and create applicaiton.css.scss and use it.

Also in rails 3 any gem that is declared inside assets group will be included only in development and test environment.

application.rb in rails 3.

if defined?(Bundler)
  # If you precompile assets before deploying to production, use this line
  Bundler.require(*Rails.groups(:assets => %w(development test)))
  # If you want your assets lazily compiled in production, use this line
  # Bundler.require(:default, :assets, Rails.env)
end

application.rb in rails 4.

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)

Try moving the gem declaration out of assets group and it should work.

idmean
  • 14,540
  • 9
  • 54
  • 83
Anirudhan J
  • 2,072
  • 6
  • 27
  • 45
1

Since Rails 3.1, new Rails projects will be already configured to use Sass (so if you are using 3.1 you don't need to add that gem). If you are upgrading to Rails 3.1 you will need to add the following to your Gemfile.

You can create it in the stylesheets folder and add the following lines to it.

/* ...
*= require_self
*= require_tree .
*/

Then in your view add

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

Also make sure you are following this guide

Try adding require statement of "bootstrap-sass" to config.ru file. A working config.ru is like the following.

# This file is used by Rack-based servers to start the application.

require ::File.expand_path('../config/environment',  __FILE__)
require 'bootstrap-sass' #require statement of bootstrap-sass
run Rails.application
Wazery
  • 15,394
  • 19
  • 63
  • 95