在Rails 3应用程序中Sass导入错误—“导入未找到或不可读的文件:compass”

时间:2021-05-25 09:15:27

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.

我有一个Rails 3应用,我在上面成功地运行了compass init ./——使用blueprint。我可以从/样式表目录中@import文件,但是当我尝试@import compass时,会得到一个错误。

Right now the app has two simple sass files:

现在这个应用有两个简单的sass文件:

common.scss

common.scss

$body-background: blue;

main.scss

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 compass or blueprint or 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_path line 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 @import statements. How do I tell Sass where to find the Compass and Blueprint libraries?

我在google上搜索了两天,无法确定为什么基本的@import语句会出现这种问题。如何告诉Sass在哪里找到指南针和蓝图库?

7 个解决方案

#1


21  

I was getting this error.

我得到了这个错误。

I changed this line in my application.rb from:

我在应用程序中更改了这一行。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.sass NOT something.sass

另外,要确保文件是name 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.

还有一件事,我有一个旧指南针。在Rails 3.2中不需要的配置目录中的rb文件。删除它也为我解决了这个问题。

#2


9  

I fixed this problem by switching to the compass-rails gem instead of the compass gem in my Gemfile (don't forget to reboot your server). Just in case someone might come across here.

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

#3


5  

I fixed this error after banging my head over it

我把头靠在上面,修正了这个错误

I commented this line in my application.rb from:

我在应用程序中注释了这一行。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

#4


4  

Okay, after help from the amazing Chris Eppstein I was able to find the offending line. In config/environments.rb I had this line:

好吧,在克里斯·埃普斯坦的帮助下,我找到了那条冒犯我的线。在config /环境。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]。

#5


3  

I fixed this problem on my Rails 3.2.0 server by moving out gem 'compass-rails', '~> 1.0.1' from the :assets group in the Gemfile, from a tip in https://github.com/Compass/compass-rails/issues/19.

通过将gem 'compass-rails'、'~> 1.0.1'从Gemfile中的:assets组移出,我在Rails 3.2.0服务器上解决了这个问题。

#6


2  

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.

看来安装中漏掉了什么。(或许是线罗盘的安装蓝图?)我遵循以下步骤:http://compass-style.org/reference/blueprint/,无法重新创建问题。

#7


0  

I fixed this error like this:

我这样修正了这个错误:

In application.rb I had

在应用程序中。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之后完成的

#1


21  

I was getting this error.

我得到了这个错误。

I changed this line in my application.rb from:

我在应用程序中更改了这一行。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.sass NOT something.sass

另外,要确保文件是name 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.

还有一件事,我有一个旧指南针。在Rails 3.2中不需要的配置目录中的rb文件。删除它也为我解决了这个问题。

#2


9  

I fixed this problem by switching to the compass-rails gem instead of the compass gem in my Gemfile (don't forget to reboot your server). Just in case someone might come across here.

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

#3


5  

I fixed this error after banging my head over it

我把头靠在上面,修正了这个错误

I commented this line in my application.rb from:

我在应用程序中注释了这一行。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

#4


4  

Okay, after help from the amazing Chris Eppstein I was able to find the offending line. In config/environments.rb I had this line:

好吧,在克里斯·埃普斯坦的帮助下,我找到了那条冒犯我的线。在config /环境。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]。

#5


3  

I fixed this problem on my Rails 3.2.0 server by moving out gem 'compass-rails', '~> 1.0.1' from the :assets group in the Gemfile, from a tip in https://github.com/Compass/compass-rails/issues/19.

通过将gem 'compass-rails'、'~> 1.0.1'从Gemfile中的:assets组移出,我在Rails 3.2.0服务器上解决了这个问题。

#6


2  

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.

看来安装中漏掉了什么。(或许是线罗盘的安装蓝图?)我遵循以下步骤:http://compass-style.org/reference/blueprint/,无法重新创建问题。

#7


0  

I fixed this error like this:

我这样修正了这个错误:

In application.rb I had

在应用程序中。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之后完成的