Reno, NV    +1 (800)0 621-0871

Go back

Bugs and Fixes | Development | Ruby on Rails

Compass, Rails 3.1 and the asset pipeline

  |  April 25, 2012

I am part of a volunteer group of developers working on a volunteer portal for the Philippines. I haven’t been helping out a lot because the main state of the site right now is that it has a lot of bugs which I think can probably be fixed easily by adding compass into it.

It is a rails 3.1.0 app and I’ve done my fair share of googling, asking in the chatroom(no replies), the mailing list(also no replies) and even in stackoverflow. At one point, I filed a bug in compass-rails and eventually they did see that it was a bug. For compass-rails to work on your rails 3.1 app, it has to be at LEAST 3.1.1

I upgraded the app to rails 3.1.3 with the ever so amazing bundler and kept trying. Every couple of weeks(yes it took me that long!), I’d try to start a new branch and try to make it work, but after a couple of hours of fiddling and googling, I’d give up. I always followed the steps mentioned in compass-rails’ github page, and I still couldn’t make it work. It still keeps giving me the error:

File to import not found or unreadable: compass/reset.

Finally, I created a new rails 3.1.3 app and then tried the instructions there. And voila! It worked! Now the only thing I had to do was to compare the files and changes on each project. I first looked into the config/ directory and by process of elimination, found these offending lines in config/application.rb

If you have a Gemfile, require the gems listed there, including any gems

you've limited to :test, :development, or :production.

Bundler.require(:default, Rails.env) if defined?(Bundler)

While I did upgrade to rails 3.1.3 using my Gemfile and bundle install, I didn’t think that the generated configuration files weren’t updated in turn. My config/application.rb was still a rails 3.1.0 version. The [working] rails 3.1.3 version had this:

if defined?(Bundler)

If you precompile assets before deploying to production, use this line

Bundler.require(*Rails.groups(:assets => %w(development test)))

If you want your assets lazily compiled in production, use this line

Bundler.require(:default, :assets, Rails.env)

end

I copied this over and everything magically worked!