[英]Error: File to import not found or unreadable: compass. in rails 3.1
[英]Sass import error in Rails 3 app - “File to import not found or unreadable: compass”
我有一個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正在工作。
如果我取消注釋該行,並嘗試導入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: }
也許我必須明確告訴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-rails
寶石而不是我的Gemfile中的compass
寶石解決了這個問題(不要忘記重新啟動服務器)。 以防有人可能會遇到這里。
我敲了敲頭后修好了這個錯誤
我在我的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之后
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.