2012-11-10 64 views
2

我是新來的資產管道,所以讓我知道如果我做錯了事情。Sass :: SyntaxError未定義變量

在SASS中使用Rails 3.2。我有一個配置partial,它定義了我想在整個scss文件中使用的一串SASS變量。根據this guide,我先輸入configuration,然後輸入bonus。但是,我不斷收到Sass::SyntaxError在bonus.css.scss中的Undefined variable: "$darkRed"。我究竟做錯了什麼?

application.css.scss

/* 
* This is a manifest file that'll be compiled into application.css, which will include all the files 
* listed below. 
* 
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, 
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. 
* 
* You're free to add application-wide styles to this file and they'll appear at the top of the 
* compiled file, but it's generally better to create a new file per style scope. 
*/ 

@import "configuration"; 
@import "bootstrap"; 
@import "bonus"; 

_configuration.css.scss

//colors 
$darkRed: #B94A48; 
$controlColor: #777; 

bonus.css.scss

div.give-inline-help .help-inline 
    { 
    color: $darkRed; 
    font-size: 15px; 
    font-family: MuseoSans-300; 
    padding-left: 0px; 
} 
+0

這是一個3歲以上的老問題......你現在將它標記爲重複? – Raphael

回答

-3

您導入具有錯誤的名稱SCSS文件中application.css.scss

取代:@import "configuration";

有:@import "_configuration";

或您的_configuration.css.scss文件重命名爲configuration.css.scss

+0

這是什麼Rails具體?因爲「配置」和「_configuration」在Rails之外的Sass中可以互換。 – cimmanon

+0

看看一個這個[多SASS文件(http://stackoverflow.com/questions/5571477/use-multiple-sass-files):「如果你的名字你導入的文件開始用下劃線,然後SASS不嘗試編譯這些。「 – Thanh

+6

你誤解是什麼意思。下劃線只是告訴Sass在編譯時不要創建一個CSS文件。這並不意味着「嘿,完全忽略這個文件的內容。」 – cimmanon

2

所以我碰上了這一點,並想給更精確的答案:

在任何@import編輯文件鏈下游非下劃線命名文件將與Sass::SyntaxError Undefined Variable中斷。

使用Sass,如果您想要覆蓋變量,則必須確保使用不間斷的下劃線鏈文件。

就這麼簡單,雖然有時很容易經過!

+0

是否有沒有乾的方式來包含這些定義下游? – jwg2s

+0

@ jwg2s - 只需保持最高級別的非下劃線,一切前面加上下劃線解決了這個問題。它種是有道理的,現在,任何不帶下劃線的文件有它自己的離散範圍,而一個下劃線文件屬於另一個人的範圍。 – kross