如何从ROR解析Sass :: SyntaxError

时间:2015-02-24 13:07:44

标签: ruby-on-rails ruby twitter-bootstrap

任何人都可以帮我解决以下错误。当我尝试访问" http://localhost:3000"它向我显示以下错误。

错误:

Sass::SyntaxError in Users#index

Showing C:/Site/bootstrap_playground/app/views/layouts/application.html.erb where line #5 raised:

File to import not found or unreadable: bootstrap-sprockets.
Load paths:
  Sass::Rails::Importer(C:/Site/bootstrap_playground/app/assets/stylesheets/users.css.scss)
  C:/Ruby193/lib/ruby/gems/1.9.1/gems/bootstrap-sass-3.1.1.1/vendor/assets/stylesheets
  (in C:/Site/bootstrap_playground/app/assets/stylesheets/users.css.scss)

我的代码如下:

的Gemfile

source 'https://rubygems.org'

gem 'rails', '3.2.19'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'sqlite3'


# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platforms => :ruby

  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'debugger'
gem 'bootstrap-sass', '~> 3.1.1.1' 

布局/ application.html.erb

<!DOCTYPE html>
<html>
<head>
  <title>BootstrapPlayground</title>
  <%= stylesheet_link_tag    "application", :media => "all" %>
  <%= javascript_include_tag "application" %>
  <%= csrf_meta_tags %>
</head>
<body>
<header class="navbar navbar-fixed-top navbar-inverse">
      <div class="container">
        <%= link_to "sample app", '#', id: "logo" %>
        <nav>
          <ul class="nav navbar-nav navbar-right">
            <li><%= link_to "Home",   '#' %></li>
            <li><%= link_to "Help",   '#' %></li>
            <li><%= link_to "Log in", '#' %></li>
          </ul>
        </nav>
      </div>
    </header>
    <div class="container">
      <%= yield %>
    </div>
</body>
</html>

的样式表/ users.css.scss

@import "bootstrap-sprockets";
@import "bootstrap";
body {
  padding-top: 60px;
}

section {
  overflow: auto;
}

textarea {
  resize: vertical;
}

.center {
  text-align: center;
}

.center h1 {
  margin-bottom: 10px;
}
h1, h2, h3, h4, h5, h6 {
  line-height: 1;
}

h1 {
  font-size: 3em;
  letter-spacing: -2px;
  margin-bottom: 30px;
  text-align: center;
}

h2 {
  font-size: 1.2em;
  letter-spacing: -1px;
  margin-bottom: 30px;
  text-align: center;
  font-weight: normal;
  color: #777;
}

p {
  font-size: 1.1em;
  line-height: 1.7em;
  }

请检查所有代码并使其正确。谢谢。

1 个答案:

答案 0 :(得分:0)

如果您使用rails 4,则不应将assets组用作

http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-3-2-to-rails-4-0-gemfile

请在Gemfile上添加以下内容来解决问题

gem 'bootstrap-sass', '3.2.0.2'

然后bundle install

重新启动服务器