Sass production woes in Rails
Thursday, March 20th, 2008Rails 2.0+ introduced our team at CitrusByte to a Sass woe: our sass file would not regenerate. We would be able to regenerate it when ssh’ing into the site and starting the server in an environment other than production. Obviously not an ideal solution. So, what’s the fix?
Place the following in any ruby file in your rails_root/config/initializers/some_file.rb:
p "** Ensuring the Sass::RAILS_LOADED is undefined for regeneration" if defined?(Sass::RAILS_LOADED) module Sass remove_const("RAILS_LOADED") end end
Here’s a technical description of the problem:
In Rails, Sass runs through the ActionController::Base.process command with an alias_method. The update_stylesheets method is never surfaced outside of there in the Rails environment; this makes it difficult to run it in a Capistrano task.
Also, the Sass file needs to be regenerated after the plugins load. It’s not ideal to place this in the environment.rb, because most of this runs before other configuration parameters. The initializers load after the plugins load and is the final block of code that is run on the init block. That makes an initializer a perfect place to put our fix.
