Ruby-on-rails Rails 3 应用程序中的 Sass 导入错误 - “未找到或无法读取导入的文件:指南针”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6005361/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Sass import error in Rails 3 app - "File to import not found or unreadable: compass"
提问by Eric Wright
I have a Rails 3 app on which I successfully ran compass init rails ./ --using blueprint. I can @importfiles from the /stylesheets directory, but I get an error when I try to @import compass.
我有一个成功运行的 Rails 3 应用程序compass init rails ./ --using blueprint。我可以@import从 /stylesheets 目录中创建文件,但是当我尝试@import compass.
Right now the app has two simple sass files:
现在该应用程序有两个简单的 sass 文件:
common.scss
常见的.scss
$body-background: blue;
main.scss
主文件
@import "common";
//@import "compass";
body {
background: $body-background;
}
With the @import "compass"line commented out, this works -- I get a blue background, so I know Sass is working.
@import "compass"注释掉该行后,这行得通——我得到了蓝色背景,所以我知道 Sass 正在工作。
If I uncomment the line, and try to import compassor blueprintor anything else, I get an error like this.
如果我取消注释该行,并尝试导入compass或blueprint其他任何内容,我会收到这样的错误。
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: }
I had through maybe I had to explicitly tell Sass where to find the Compass gem, so I added an add_import_pathline to config/compass.rb:
我已经完成了,也许我必须明确告诉 Sass 在哪里可以找到 Compass gem,所以我add_import_path在 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 have been googling for two days, and can't determine why I'm having this problem with basic @importstatements. How do I tell Sass where to find the Compass and Blueprint libraries?
我已经用谷歌搜索了两天,无法确定为什么我的基本@import语句会出现这个问题。我如何告诉 Sass 在哪里可以找到指南针和蓝图库?
采纳答案by Eric Wright
Okay, after help from the amazing Chris Eppstein I was able to find the offending line. In config/environments.rbI had this line:
好的,在令人惊叹的 Chris Eppstein 的帮助下,我找到了违规行。在config/environments.rb我有这条线:
Sass::Plugin.options[:template_location] = {
"#{RAILS_ROOT}/app/stylesheets" => "#{RAILS_ROOT}/public/stylesheets"
}
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.0.7)和 Compass(0.11.1),这条线不是必需的。我是按照教程添加的。如果 sass 找不到指南针,那可能是因为这条线把你的Sass::Plugin.options[:template_location].
回答by Jonathon Horsman
I was getting this error.
我收到这个错误。
I changed this line in my application.rb from:
我将 application.rb 中的这一行从:
Bundler.require(:default, Rails.env) if defined?(Bundler)
to:
到:
Bundler.require(*Rails.groups(:assets => %w(development test))) if defined?(Bundler)
Also, make sure the files are names something.css.sassNOT something.sass
另外,请确保文件的名称为something.css.sass 而不是something.sass
And one other thing, I had an old compass.rb file in my config directory which isn't needed in Rails 3.2. Deleting that also solved this problem for me.
还有一件事,我的 config 目录中有一个旧的 compass.rb 文件,Rails 3.2 不需要它。删除它也为我解决了这个问题。
回答by Jasper Kennis
I fixed this problem by switching to the compass-railsgem instead of the compassgem in my Gemfile (don't forget to reboot your server). Just in case someone might come across here.
我通过在我的 Gemfile 中切换到compass-railsgem 而不是 gem 来解决这个问题compass(不要忘记重新启动你的服务器)。以防万一有人遇到这里。
回答by Abhra Basak
I fixed this error after banging my head over it
我把头撞在上面后修复了这个错误
I commented this line in my application.rb from:
我在我的 application.rb 中评论了这一行:
Bundler.require(*Rails.groups(:assets => %w(development test))) if defined?(Bundler)
and uncommented:
并取消注释:
Bundler.require(:default, :assets, Rails.env) if defined?(Bundler)
I am using Rails 3.2.11
我正在使用 Rails 3.2.11
回答by ecmanaut
I fixed this problem on my Rails 3.2.0 server by moving out gem 'compass-rails', '~> 1.0.1'from the :assetsgroup in the Gemfile, from a tip in https://github.com/Compass/compass-rails/issues/19.
我通过gem 'compass-rails', '~> 1.0.1'从https://github.com/Compass/compass-rails/issues/19 中的提示移出中的:assets组,在我的 Rails 3.2.0 服务器上解决了这个问题。Gemfile
回答by MattMcKnight
The @import command in Sass imports .scss or .sass files, not .css files.
Sass 中的 @import 命令导入 .scss 或 .sass 文件,而不是 .css 文件。
It looks like something was missed in the install. (maybe the line compass install blueprint?) I followed the steps here:
http://compass-style.org/reference/blueprint/and was unable to recreate the issue.
看起来安装中遗漏了一些东西。(也许是线路compass install blueprint?)我按照以下步骤操作:http:
//compass-style.org/reference/blueprint/并且无法重现该问题。
回答by Thinley Koblensky
I fixed this error like this:
我像这样修复了这个错误:
In application.rb I had
在 application.rb 我有
Bundler.require(:default, Rails.env) if defined?(Bundler)
and changed to
并改为
Bundler.require(:default, :assets, Rails.env) if defined?(Bundler)
This was after updating a project from 3.0.3 to 3.2.13
这是在将项目从 3.0.3 更新到 3.2.13 之后

