在SCSS部分中使用Rails 3.1资产路径 [英] Use Rails 3.1 Asset Paths in a SCSS Partial

查看:66
本文介绍了在SCSS部分中使用Rails 3.1资产路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下设置:

app/assets/stylesheets/application.css.scss

/*
*= require_self
*= require fancybox
*/

/* COLORS.. */
/* MIXINS... */
/* FONT STACKS... */

/* IMPORTS */
@import "reset";
@import "supergrid";
@import "rails";
@import "app";
@import "forms";
@import "layout";

在我的各个部分中,资产路径确实存在问题.在application.css.scss或清单加载的任何内容中时,我可以使用:

In my various partials I'm having a real problem with the asset paths. When inside application.css.scss or anything loaded by the manifest, I can use:

.example { background-image: image-path("background.png"); }

但是,当我使用部分内容(例如_layout.css.scss部分)时,当我尝试相同的操作时,只会从编译文件中省略background-image属性.看来SCSS资产助手在局部文件中不可用?

However, when I'm using a partial, such as my _layout.css.scss partial, when I try the same thing the background-image property is simply omitted from the compiled file. It seems the SCSS asset helpers are not available inside partials?

有人能做到这一点吗,我错过了明显的东西吗?还是根本不可能在部分中使用资产助手?如果是这样,这将是一个主要的主要问题,因为我的整个应用程序结构都取决于部分之间共享的SCSS变量和mixin.

Has anyone gotten this to work, am I missing something obvious? Or is it simply impossible to use asset helpers in partials? If so this is a major, MAJOR problem, as my entire app structure depends on SCSS variables and mixins which are shared among the partials.

我知道链表清单中没有共享变量和混合变量,因此,如果局部变量无法访问资产助手,那么我正在考虑将所有内容连接到单个scss文件中,这几乎违背了两个Sass的目的.和链轮.

I know that variables and mixins are not shared across the sprockets manifest, so if partials cannot access the asset helpers then I'm looking at having to concatenate everything into a single scss file, which pretty much defeats the purpose of both Sass and Sprockets.

任何帮助将不胜感激!

推荐答案

奇怪,它应该可以工作.

Strange, it should work.. Just few ideas:

  1. 您是否正在使用最新的宝石sass-rails和链轮?
  2. 尝试将.css.scss重命名为.scss
  3. 尝试将image-path('background.png')替换为asset-url('background.png', image)image-url('background.png')
  4. 尝试从application.css.scss中删除require_self
  5. 尝试从application.css.scss中删除所有指令,并使用@import导入这些文件
  1. Are you using up-to-date gems sass-rails and sprockets?
  2. Try to rename .css.scss to .scss
  3. Try to replace image-path('background.png') with asset-url('background.png', image) or image-url('background.png')
  4. Try to remove require_self from application.css.scss
  5. Try to remove all directives from application.css.scss and import those files with @import

这篇关于在SCSS部分中使用Rails 3.1资产路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆