Rails 3应用程序中的Sass导入错误 – “导入未找到或无法读取的文件:指南针”

我有一个Rails 3应用程序,我成功运行compass init rails ./ --using blueprint 。 我可以从/ stylesheets目录中@import文件,但是当我尝试@import compass时出现错误。

现在该应用程序有两个简单的sass文件:

common.scss

 $body-background: blue; 

main.scss

 @import "common"; //@import "compass"; body { background: $body-background; } 

随着@import "compass"线的注释,这个工作 – 我得到一个蓝色的背景,所以我知道Sass正在工作。

如果我取消注释该行,并尝试导入compassblueprint或其他任何东西,我会收到这样的错误。

 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在哪里找到Compass gem,所以我在config / compass.rb中添加了一个add_import_path行:

 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" 

我一直在谷歌搜索两天,并无法确定为什么我的基本@import语句有这个问题。 如何告诉Sass在何处找到Compass和Blueprint库?

我收到了这个错误。

我在application.rb中改变了这一行:

 Bundler.require(:default, Rails.env) if defined?(Bundler) 

至:

 Bundler.require(*Rails.groups(:assets => %w(development test))) if defined?(Bundler) 

另外,请确保文件名为something.css.sass NOT something.sass

另外一件事,我的配置目录中有一个旧的compass.rb文件,这在Rails 3.2中是不需要的。 删除它也为我解决了这个问题。

我通过切换到compass-railsgem而不是我的Gemfile中的compassgem解决了这个问题(不要忘记重新启动服务器)。 以防有人可能会遇到这里。

我敲了敲头后修好了这个错误

我在我的application.rb中评论了这一行:

 Bundler.require(*Rails.groups(:assets => %w(development test))) if defined?(Bundler) 

并且没有注释:

 Bundler.require(:default, :assets, Rails.env) if defined?(Bundler) 

我正在使用Rails 3.2.11

好的,在惊人的Chris Eppstein的帮助下,我找到了令人讨厌的线路。 在config/environments.rb我有这一行:

 Sass::Plugin.options[:template_location] = { "#{RAILS_ROOT}/app/stylesheets" => "#{RAILS_ROOT}/public/stylesheets" } 

对于当前版本的Rails(我有3.0.7)和Compass(0.11.1),这一行不是必需的 。 我按照教程后添加了它。 如果sass找不到指南针,可能是因为这行搞砸了你的Sass::Plugin.options[:template_location]

我在我的Rails 3.2.0服务器上修复了这个问题,从https://github.com/Compass中的一个提示中Gemfile:assets组中的Gemfile gem 'compass-rails', '~> 1.0.1' / compass-rails / issues / 19 。

Sass中的@import命令导入.scss或.sass文件,而不是.css文件。

看起来安装中遗漏了一些东西。 (也许是compass install blueprint ?)我按照这里的步骤操作: http : //compass-style.org/reference/blueprint/并且无法重新创建问题。

我修复了这个错误:

在application.rb我有

 Bundler.require(:default, Rails.env) if defined?(Bundler) 

并改为

 Bundler.require(:default, :assets, Rails.env) if defined?(Bundler) 

这是在将项目从3.0.3更新到3.2.13之后