Using Compass with Rails 3.1 final and no hacks

The web is full of complicated instructions about getting the Compass CSS framework to work with Rails 3.1 & the asset pipeline when actually you don’t need to do anything any more.

All you need to do, is add Compass to your Gemfile and you should be all set. You can even group it under assets (so long as you precompile assets before deploying).

But you might find it still doesn’t work, that’s because the stable version of Compass (0.11) doesn’t work with Rails 3.1. So you need to explicitly request version 0.12:

group :assets do
  gem 'sass-rails', "  ~> 3.1.0"
  gem 'coffee-rails', "~> 3.1.0"
  gem 'uglifier'
  gem 'compass', '~> 0.12.alpha'
end

Now you can carry on using the great Rails 3.1 asset pipeline with all the Compass and Blueprint mix-ins you want.

This entry was posted in Blog, Ruby. Bookmark the permalink.
  • I’ve been struggling with this for quite awhile. Every time I run the familiar ‘compass watch’ from my shell it says “Nothing to compile. If you’re trying to start a new project, you have left off the directory argument. Run “compass -h” to get help.”

    No ie / print / base.css.scss files were generated: When I use the old compass init I get the old directly structure. 

    How do I get things to work like they do in Rails 3.0.10?

    • You shouldn’t need to run compass watch at all. The Rails gem recompiles your stylesheets when you request them in development mode.

      You don’t even need to run compass init for Rails 3.1 any more. So long as you install the alpha version, you can just write stylesheets in the new app/assets/stylesheets folder with all the Compass mix-ins you want 🙂

  • Trung LE

    This is what I’ve been looking for, I was playing around just try to understand why the rails init create stylesheets in apps/stylesheets which is so not rails 3.1. Thanks for this piece of info

  • Giang Nguyen

    Compass is now 0.12.1 and works with Rails 3.1+ without any hack. Actually I dont’ understand the value of Compass in Rails 3.1+

    • Compass provides lots of useful mix-ins for SASS.