我得到NameError - 未初始化的常量Sass :: Engine:当我用sass gem运行我的sinatra应用程序时。 用rbenv安装了ruby版本2.3.1并安装了sinatra,sass gem。
require 'sinatra'
require 'slim'
require 'sass' # required sass
require 'sinatra/reloader' if development?
get '/styles.css' do
scss :styles #does not generate styles.css, styles.scss file is in /views folder
end
get '/' do
slim :home
end
get '/about' do
@title = "All About This Website"
slim :about
end
get '/contact' do
slim :contact #, :layout => :special
end
not_found do
slim :not_found
end
get '/fake_error' do
status 500
"There's nothing wrong, really :P"
end
完整错误:
NameError - 未初始化的常量Sass :: Engine: /home/tasqyn/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/tilt-2.0.5/lib/tilt/sass.rb:13:in
prepare' /home/tasqyn/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/tilt-2.0.5/lib/tilt/template.rb:92:in
初始化” /home/tasqyn/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:862:in 在compile_template中阻止new' /home/tasqyn/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:862:in
/home/tasqyn/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/tilt-2.0.5/lib/tilt.rb:104:inblock in fetch' /home/tasqyn/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/tilt-2.0.5/lib/tilt.rb:103:in
取” /home/tasqyn/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/tilt-2.0.5/lib/tilt.rb:103:infetch' /home/tasqyn/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:841:in
compile_template” /home/tasqyn/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:822:inrender' /home/tasqyn/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:687:in
scss'main.rb:7:在'block in'中
我做错了什么?
这里是styles.scss:
$red: #903;
$black: #444;
$white: #fff;
$main-font: Helvetica, Arial, sans-serif;
body {
font-family: $main-font;
}
h1 {
color: $red;
font: 32px/1 $main-font;
}
header h1 {
font-size: 40px;
line-height: 80px;
background: transparent url(/images/logo.png) 0 0 no-repeat;
padding-left: 84px;
}
@mixin tabs ($background: blue, $color: yellow) {
ul {
list-style: none;
margin: 0;
padding: 0;
background: $background;
overflow: hidden;
}
li {
float: left;
}
a {
text-decoration: none;
display: block;
padding: 8px;
background: $background;
color: $color;
&:hover {
background: darken($background, 20%);
}
}
}
nav {
@@include tabs($background: $black, $color: $white);
font-weight: bold;
}
p {
font: 13px/1.4 $main-font;
}
答案 0 :(得分:3)
将任何此宝石添加到您的宝石文件gem 'bootstrap-sass'
或gem 'sass-rails'
然后使用bundle
或bundle install
命令
答案 1 :(得分:1)
确保你的宝石文件中有:
gem 'sass'
gem 'sass-rails'
如果没有,请添加它。不要忘记运行bundle install。
答案 2 :(得分:0)
在我的方案中,(运行rails 3.2.22.2)在我的应用程序工作的一台机器上。
在另一台机器上我克隆了repo并遇到了uninitialized constant Sass::Engine
错误。
我将gem 'sass-rails'
移出group :assets do
块。
这不适合我。
rake assets:clean
删除所有已编译的资源。
下次运行rake rails s
时,您的资产将被重新编译
如果没有,您可以运行rake assets:precompile
来编译您的所有资产
或者,如果您通过capistrano进行部署,则deploy.rb将运行" deploy:assets:precompile"并为您的生产/暂存机器编译资产。
似乎发生错误是因为没有正确地在资产管道中编译sass。 (如果有人得到答案,我很想知道为什么会这样)