简体   繁体   English

Rails 3.1:从Lib导入Sass

[英]Rails 3.1: Sass Import from Lib

I've got a bunch of 'bootstrap' sass files I'd like to stick in my applications /lib directory, following the new conventions of the asset pipeline. 我有一堆'bootstrap'sass文件,我想按照资产管道的新约定,粘贴在我的applications /lib目录中。

However, I need to import these into my application.css.scss rather than requiring them, as I would like to share some color variables etc. throughout the app. 但是,我需要将这些导入到我的application.css.scss而不是要求它们,因为我想在整个应用程序中共享一些颜色变量等。 I have not been able to figure out a way to get @import to grab a .scss file from /lib/assets/stylesheets . 我无法找到让@import/lib/assets/stylesheets获取.scss文件的方法。

Any suggestions? 有什么建议么?

@import should look for any .css.scss files located in your assets load path, be it in app/assets/stylesheets , lib/assets/stylesheets , vendor/assets/stylesheets , or any additional paths added by gems, so it's odd that you're getting an error. @import 应该查找位于资产加载路径中的任何.css.scss文件,无论是在app/assets/stylesheetslib/assets/stylesheetsvendor/assets/stylesheets ,还是由gem添加的任何其他路径,所以它很奇怪你收到了错误。

Note you do not need to pass a folder name when using @import unless the file is in a subdirectory of assets/stylesheets - sass-rails will look through every folder on your load path and see if the resource exists relative to those folders. 请注意,在使用@import时不需要传递文件夹名称,除非该文件位于assets/stylesheets的子目录中 - sass-rails将查看加载路径上的每个文件夹,并查看相对于这些文件夹的资源是否存在。

To ensure that lib/assets/stylesheets is in your assets load path (which it should be, since it's a default option) crack open a Rails prompt and type Rails.application.config.assets.paths . 要确保lib/assets/stylesheets位于资产加载路径中(它应该是,因为它是默认选项),请打开Rails提示并键入Rails.application.config.assets.paths As an example, here's the result for one of my applications: 举个例子,这是我的一个应用程序的结果:

ruby-1.9.3-p0 :012 > Rails.application.config.assets.paths
 => ["/Users/tom/ruby/qa/app/assets/images",
 "/Users/tom/ruby/qa/app/assets/javascripts",
 "/Users/tom/ruby/qa/app/assets/stylesheets", 
 "/Users/tom/ruby/qa/lib/assets/stylesheets",
 "/Users/tom/ruby/qa/vendor/assets/javascripts",
 "/Users/tom/ruby/qa/vendor/assets/stylesheets",
 "/Users/tom/.rvm/gems/ruby-1.9.3-p0/gems/jquery-rails-1.0.14/vendor/assets/javascripts",
 "/Users/tom/.rvm/gems/ruby-1.9.3-p0/gems/bootstrap-sass-1.4.0/vendor/assets/javascripts", 
 "/Users/tom/.rvm/gems/ruby-1.9.3-p0/gems/bootstrap-sass-1.4.0/vendor/assets/stylesheets"] 

It's also worth ensuring that sass-rails is up to date and running the latest version, since I believe early versions had limit support in terms of cross-folder @import . 同样值得确保sass-rails是最新的并运行最新版本,因为我认为早期版本在跨文件夹@import方面有限制支持。

NB: I also believe that convention suggests files such as Bootstrap or jQuery should go in your vendor/assets folder rather than lib/assets 注意:我也相信会议建议像Bootstrap或jQuery这样的文件应该放在你的vendor/assets文件夹而不是lib/assets

我遇到了同样的问题,这是因为我在将文件添加到lib目录后忘记了重启服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM