Getting Sass or Scss Compass running on Rails 4

Written by on Aug 2 2013
compass sass rails4

I’ve been working on a small Rails 4 app. I had finally made enough progress that it was time to get Allan involved. He’s a big fan of Compass and found a bug that he couldn’t figure out almost as soon as he started.

When changed the .css.sass file with below code snipped the error happened.

    @import compass

File to import not found or unreadable: compass

At first this seems like a pathing issue, but a quick google search shows that Compass doesn’t support Rails 4 yet. A lot of people reported that it was working for them and had little hacks here and there, but none of them worked for me. (The most significant hack was to use a different branch, more on that below.) Finally we decided to migrate our Rails 4 app to Rails 3. It didn’t take that long to do (not a lot of new things in Rails 4), but to my horror I had the same error in Rails 3. This made me think perhaps it was something in my app, so I made a fresh Rails 4 app and it worked. Obviously I went one step at a time until I traced the source of the problem: Don’t put the gem declaration in the assets group of your gem file. Boom, it works. You also have to use the “rails4-hack” branch of the gem.

Here’s what my Gemfile looks like now:

gem "haml-rails"
gem 'sass-rails'
gem 'compass-rails', github: "Compass/compass-rails", branch: "rails4-hack"
group :assets do

One last note: The Compass lib files are stored in RAILS_ROOT/tmp/cache/assets. This means it’s possible for you to have everything working, then have a developer come alone and move the gem declaration into the assets group, and have everything keep working. Until deploy time, a new developer comes on the project, or someone clears tmp, then boom!

Also thanks to Chris Your of Ignition Industries for giving us some assistance via Twitter.


Hi I'm Steven,

I wrote the article you're reading... Steve is the cofounder of LessEverything. He's also cofounder (now single dad) of three beautiful children. His interests are health, exercise, the beach, looking beautiful, and dancing at inappropriate moments.

Get Blog Updates