2011-06-21 22 views
0

rails hackers。红宝石在rails上使用sass自动加载语法错误

我的rails项目运行时应用css加载是没问题的。但如果使用sass文件转换为css,在Web浏览器中的语法错误消息。

这是我的操作系统和内核环境以及运行信息的rails上的ruby。

的Linux的localhost.localdomain 2.6.18-238.9.1.el5#1 SMP星期二月12十八点10分13秒EDT 2011 x86_64的x86_64的x86_64的GNU/Linux的

CentOS版本5.6(最终)


Ruby on Rails using GemFile in rails project directory. 
... 
gem 'rails', '3.0.5' 

gem "haml" 
... 

Using rake (0.9.2) 
Using abstract (1.0.0) 
Using activesupport (3.0.5) 
Using builder (2.1.2) 
Using i18n (0.6.0) 
Using activemodel (3.0.5) 
Using erubis (2.6.6) 
Using rack (1.2.3) 
Using rack-mount (0.6.14) 
Using rack-test (0.5.7) 
Using tzinfo (0.3.28) 
Using actionpack (3.0.5) 
Using mime-types (1.16) 
Using polyglot (0.3.1) 
Using treetop (1.4.9) 
Using mail (2.2.19) 
Using actionmailer (3.0.5) 
Using arel (2.0.10) 
Using activerecord (3.0.5) 
Using activeresource (3.0.5) 
Using annotate (2.4.0) 
Using bcrypt-ruby (2.1.4) 
Using bundler (1.0.13) 
Using orm_adapter (0.0.5) 
Using warden (1.0.4) 
Using devise (1.2.rc) 
Using event-calendar (2.3.3) 
Using gem_plugin (0.2.3) 
Using haml (3.1.2) 
Using liquid (2.2.2) 
Using meta_search (1.0.5) 
Using mongrel (1.2.0.pre2) 
Using mysql2 (0.2.7) 
Using net-ssh (2.1.4) 
Using net-sftp (2.0.5) 
Using paperclip (2.3.11) 
Using thor (0.14.6) 
Using railties (3.0.5) 
Using rails (3.0.5) 
Using recaptcha (0.3.1) 
Using ruby-ole (1.2.11.1) 
Using rufus-scheduler (2.0.9) 
Using simple_form (1.4.1) 
Using spreadsheet (0.6.5.4) 
Using will_paginate (3.0.pre2) 

[[email protected] stylesheets]$ sass -v 
Sass 3.1.2 (Brainy Betty) 
[[email protected] stylesheets]$ compass -v 
Compass 0.11.3 (Antares) 

below error message webbrowser loading.. 

Syntax error: Invalid variable: "$global_main_width = 600px". 
     on line 7 of /home/test/rails_projects/blog/public/stylesheets/sass/blog_style.sass 

2: @import form 
3: @import mixin 
4: @import popup 
5: 
6: 
7: $global_main_width = 600px 
8: $global_side_width = 200px 
9: $global_wrapper_margin = 10px 
10: 

Syntax error: Invalid variable: "$x = (($col - 1) * -$width) - (($col - 1) * $margin)". 
     on line 23 of 

18:  :width $width 
19: @if $height != "default" 
20:  :height $height 
21: 
22: =sprite_position($col, $row, $width, $height, $margin) 
23: $x = (($col - 1) * -$width) - (($col - 1) * $margin) 
24: $y = (($row - 1) * -$height) - (($row - 1) * $margin) 
25: :background-position $x $y 

回答

1

等号是什么是你扔。对于SASS语法使用的是:

$global_main_width: 600px 

对于SCSS其坚持更接近普通的CSS语法,你需要分号:

$global_main_width: 600px; 
+0

请推荐给我。链接很好如何使用sass转换为rails3项目中的CSS。 – moonlightcastleknight

0

而是使用的冒号尝试等号:

$global_main_width: 600px; 
$global_side_width: 200px; 
$global_wrapper_margin: 10px; 

来自fine manual

使用SassScript最直接的方法是使用变量。变量开始美元符号,和被设置等的CSS属性:

$width: 5em; 

[...]

变量也被用于与被限定=而非:;这仍然有效,但它已被弃用,并打印出警告。 :是推荐的语法。

等号应该可以工作,但它们已被弃用,并且警告可能会令人困惑。

+0

更改使用sass文件的语法?我的铁轨项目在几个月前运行良好。 – moonlightcastleknight

+0

@moonlightcastleknight:'='应该仍然有效,但最近的升级可能会禁用旧的弃用语法。 –