Rails 读 Ruby on Rails Tutorial 遇到的问题

davidminaki · 2014年04月15日 · 最后由 davidminaki 回复于 2014年04月16日 · 3076 次阅读

环境是 rails 4.1 对着书敲代码 第 5 章的时候报错

Sass::SyntaxError in StaticPages#home
Showing /home/david/begin/sample_app/app/views/layouts/application.html.erb where line #5 raised:

Undefined variable: "$grayLight".
  (in /home/david/begin/sample_app/app/assets/stylesheets/custom.css.scss:58)

其中 custom.css.scss 代码如下




@import "bootstrap";

//= depend_on_asset "bootstrap/glyphicons-halflings-regular.eot"
//= depend_on_asset "bootstrap/glyphicons-halflings-regular.svg"
//= depend_on_asset "bootstrap/glyphicons-halflings-regular.ttf"
//= depend_on_asset "bootstrap/glyphicons-halflings-regular.woff"

$grayMediumLight: #eaeaea;


/* universal */

html {
  overflow-y: scroll;
}

body {
  padding-top: 60px;
}

section {
  overflow: auto;
}

textarea {
  resize: vertical;
}

.center {
  text-align: center;
  h1 {
    margin-bottom: 10px;
  }
}

/* typography */

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: $grayLight;
}

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


/* header */

#logo {
  float: left;
  margin-right: 10px;
  font-size: 1.7em;
  color: white;
  text-transform: uppercase;
  letter-spacing: -1px;
  padding-top: 9px;
  font-weight: bold;
  line-height: 1;
  &:hover {
    color: white;
    text-decoration: none;
  }
}

/* footer */

footer {
  margin-top: 45px;
  padding-top: 5px;
  border-top: 1px solid $grayMediumLight;
  color: $grayLight;
  a {
    color: $gray;
    &:hover {
      color: $grayDarker;
    }
  }
  small {
    float: left;
  }
  ul {
    float: right;
    list-style: none;
    li {
      float: left;
      margin-left: 10px;
    }
  }
}

你没有定义 $grayLight 啊,顶部只定义了 $grayMediumLight: #eaeaea;

#1 楼 @hlcfan 书中的代码如此 不知到怎么回事

看看你用的 Bootstrap 版本是不是 3。你看的书用的是 Bootstrap2 版本。3 和 2 相比有很大改变,其中一个就是变量的名字。以前是 camel case 类似$grayLight, 现在是 hyphen 类似$gray-light。是 3 的话把变量名改一下就行了,还有问题可以自己查找 Bootstrap 文档看看新的变量名。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号