问题描述
我有一个Rails 3应用程序,在该应用程序上我成功运行了 compass init rails ./-使用蓝图
。我可以从/ stylesheets目录中 @import
文件,但是当我尝试 @import罗盘
时出现错误。
I have a Rails 3 app on which I successfully ran compass init rails ./ --using blueprint
. I can @import
files from the /stylesheets directory, but I get an error when I try to @import compass
.
现在该应用程序具有两个简单的sass文件:
Right now the app has two simple sass files:
common.scss
$body-background: blue;
main.scss
@import "common";
//@import "compass";
body {
background: $body-background;
}
使用 @import compass
行注释掉了,这行得通-我的背景是蓝色的,所以我知道Sass在工作。
With the @import "compass"
line commented out, this works -- I get a blue background, so I know Sass is working.
如果我取消注释该行,然后尝试导入罗盘
或蓝图
或其他任何东西,我得到这样的错误。
If I uncomment the line, and try to import compass
or blueprint
or anything else, I get an error like this.
Syntax error: File to import not found or unreadable: compass.
Load paths:
/Users/eric/path/to/myrailsapp/app/stylesheets
on line 2 of /Users/eric/path/to/myrailsapp/app/stylesheets/main.scss
1: @import "common";
2: @import "compass";
3:
4: body {
5: background: $body-background;
6: }
我曾经经历过,也许我不得不明确地告诉Sass在哪里找到指南针gem,所以我在config / compass.rb中添加了 add_import_path
行:
I had through maybe I had to explicitly tell Sass where to find the Compass gem, so I added an add_import_path
line to config/compass.rb:
require 'compass'
require 'html5-boilerplate'
project_type = :rails
project_path = RAILS_ROOT if defined?(RAILS_ROOT)
add_import_path "/Library/Ruby/Gems/1.8/gems/" # unfortunately this has no effect
http_path = "/"
css_dir = "public/stylesheets"
sass_dir = "app/stylesheets"
images_dir = "public/images"
javascripts_dir = "public/javascripts"
cache_dir = "tmp/sass-cache"
http_images_path = "/images"
http_stylesheets_path = "/stylesheets"
http_javascripts_path = "/javascripts"
I已经搜寻了两天,无法确定为什么我在基本的 @import
语句中遇到了这个问题。
I have been googling for two days, and can't determine why I'm having this problem with basic @import
statements. How do I tell Sass where to find the Compass and Blueprint libraries?
推荐答案
好吧,在出色的Chris Eppstein的帮助下,我是如何告诉Sass的?能够找到违规行。在 config / environments.rb
中,我有以下一行:
Okay, after help from the amazing Chris Eppstein I was able to find the offending line. In config/environments.rb
I had this line:
Sass::Plugin.options[:template_location] = {
"#{RAILS_ROOT}/app/stylesheets" => "#{RAILS_ROOT}/public/stylesheets"
}
使用当前版本的Rails (我有3.0.7)和指南针(0.11.1),此行不必要。我在完成教程后添加了它。如果sass找不到指南针,可能是因为这行弄乱了您的 Sass :: Plugin.options [:template_location]
。
With the currently versions of Rails (I have 3.0.7) and Compass (0.11.1) this line is not necessary. I added it after following a tutorial. If sass can't find compass, it might be because this line is messing up your Sass::Plugin.options[:template_location]
.
这篇关于Rails 3应用中的Sass导入错误-“找不到要导入的文件或不可读的文件:指南针”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!