Rails 3.1: Sass Import from Lib

I have a bunch of bootable sass files that I would like to use in my /lib application directories, following the new asset pipeline conventions.

However, I need to import them into my application.css.scss , and not require them, since I would like to share some color variables, etc. throughout the application. I could not find a way to get @import to grab the .scss file from /lib/assets/stylesheets .

Any suggestions?

+6
source share
2 answers

@import should look for any .css.scss files located in the download path of your resource, be it in app/assets/stylesheets , lib/assets/stylesheets , vendor/assets/stylesheets or any additional paths added by precious stones, so it’s odd, error receiving.

Please note: you do not need to pass the folder name when using @import if the file is not in the assets/stylesheets - sass-rails subdirectory, which will look at each folder of your download path and see if the resource exists relative to these folders.

To ensure that lib/assets/stylesheets is in the download path of your resource (what it should be, as it is by default), open a Rails prompt and enter Rails.application.config.assets.paths . As an example, here is 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 checking that sass-rails date and working with the latest version, as I believe that earlier versions had limited support in the @import cross-folder.

NB: I also think the convention assumes that files like Bootstrap or jQuery should go in your vendor/assets folder, not lib/assets

+10
source

I had the same problem, and that was because I forgot to restart the server after adding the files to the lib directory.

+8
source

Source: https://habr.com/ru/post/900906/


All Articles