Using Sprockets in Rails 3.1 can be a little tricky. It wasn’t hard to get Sprockets compiling CSS files from SASS into CSS. However, it became difficult when we wanted to use a compass mixin and put erb assets into our sass files. Here’s what we did to get it to work
1. Install the SASS-Rails gem
Note that this gem is NOT a replacement for SASS just an add-on to help SASS work better with Rails 3.1
2. Update your asset_path and asset_url calls
If you’ve written any sass.erb files in using the <%= asset_path... %>
tags they are replaced with asset_path("filename", type)
and/or asset_url("filename", type)
, no longer are wrapped in the <%= %>
tag.
3. Update your SASS load_path to find compass or other sass based gems you’ve installed with config.sass.load_paths in your application.rb
4. Import the compass mixins you want into your application.css.scss file
Awesome! Just what I was looking for!
thanks!
Zoga: some of this information might be out of date. With the full release of rails 3.1 I believe the SASS settings are no longer needed. Also the url helper may have changed.
url helper wasn’t changed(at least it’s working as expected). Dunno about SASS settings(I’m not using them in 3.1 and everything looks fine)
I was having a tough time getting compass to work in Rails 3.1 (after reading several other forums and posts) until I added the load_paths in your directions to application.rb. Thanks a bunch!