Search code examples
ruby-on-rails-3.1sasscompass-sasshtml5boilerplate

Is there a valid Gemfile for Rails 3.1 together with Scss, Haml, Compass and HTML-Boilerplate in production mode?


I have a successful Rails 3.0.x project with the following subset of Gems in the Gemfile:

gem "compass"
gem "haml"
gem "haml-rails"
gem "html5-boilerplate"

I tried today to upgrade to Rails 3.1 and keep all functionality, and had numerous problems in doing so. I did not yet find a configuration that did work for me in production mode, so I am working now with developing mode.

I followed the following advices here:

  • "Upgrading to Rails 3.1" from Railscast: very good as usual, and told me how to change production.rb, development.rb and application.rb to update the configuration for the asset pipeline. But did not touch compass, sass, and html5-boilerplate.
  • "Setup html-boilerplate with Rails 3.1" That contained the best fit for me, but does not work, because the method ie_html is not available in production mode. The change in the Gemfile is noted down
  • "Unable to get Rails 3.1, Compass, Sass, Blueprint working on Heroku Cedar" This did not work for me at all, I had problems to the the assets compiled then. There the try was to have everything global, because there is a dependency between Compass and Html-Boilerplate, and Html-Boilerplate has to be global due to the method ie_html.
  • Every try to use only some the Gems in the group :assets block was not successful. Most of the time, the dependency between e.g. compass and sass, or compass and html5-boilerplate could not be fulfilled.

So my question is: Is there a working Gemfile which allows to use Haml, Sass, Compass, Html5-Boilerplate and of course Rails 3.1 together?

New Gemfile working in development mode, but not in production mode:

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

I have tried to create a fresh Rails 3.1 application, and added there an image resource. There everything is working fine, so no difference between development mode and production mode. In my migrated application, I have now the following state:

  • Works well in development mode.
  • Disable some of the html5-boilerplate things to work around the problems in production.
  • Does not find yet the precompiled images in production mode.

Solution

  • First my apologies for adding another answer, but I think the history is helpful for others.

    I tried again (thank's to the comment of @theanym) to create a new application with rails 3.1.1, html5-boilerplate, compass, sass and haml, and I found a working solution for development and production mode.

    These are the steps I have taken:

    1. I started with a new application and followed there the recipe "Setup html5-boilerplate with Rails 3.1".
    2. When I started the application (in development mode), it worked nicely.
    3. When I started then in production mode, I got the following error:

      c:\apps\ruby\rails3\not>rails s -e production
      C:/apps/ruby/ruby192/lib/ruby/gems/1.9.1/gems/html5-boilerplate-1.0.0/lib/html5-boilerplate.rb:1:in `<top (required)>': 
        uninitialized constant Object::Compass (NameError)
          from C:/apps/ruby/ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `require'
      
    4. I then changed the Gemfile (only the relevant part):

      group :assets do
        gem 'sass-rails',   '~> 3.1.4'
        gem 'coffee-rails', '~> 3.1.1'
        gem "compass", '~> 0.12.alpha.0', :group => :production
        gem 'html5-boilerplate', :group => :production
        gem 'uglifier', '>= 1.0.3'
      end
      

    The relevant part of the solution for me was to denote for compass and html5-boilerplate that additional argument :group => :production.

    I then had to precompile the assets, and had to change style.scss to style.css.scss, but that was a minor tweak. Tested the application both with development and production mode, and there seems to be no error.