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.
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. I have not been able to figure out a way to get @import
to grab a .scss
file from /lib/assets/stylesheets
.
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.
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.
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
. 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
.
N.B: I also believe that convention suggests files such as Bootstrap or jQuery should go in your vendor/assets
folder rather than lib/assets
I had the same problem, and it was because i forgot restart server after add files to lib directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With