user2911232
user2911232

Reputation:

Can't find application.css.scss in my Rails app

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.

Upvotes: 2

Views: 3285

Answers (2)

Anirudhan J
Anirudhan J

Reputation: 2072

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.

Upvotes: 3

Wazery
Wazery

Reputation: 15863

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

Upvotes: 1

Related Questions