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
andapplication.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 开发者_StackOverflow中文版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.
I have it working on Heroku Cedar.
gem "rails", "~> 3.1.0"
gem 'sass-rails', "~> 3.1.0"
group :assets do
gem 'coffee-rails', "~> 3.1.0"
gem 'uglifier'
gem 'compass', '~> 0.12.alpha.0'
gem 'html5-boilerplate'
end
But before git push heroku
first precompile locally with:
RAILS_ENV=production bundle exec rake assets:precompile
then add all public/assets to your git repo and commit. Then:
git push heroku master
Heroku will detect the public/assets/manifest.yml
file and just use these files.
This works for me so should work! Cheers
Just to include some of the information that may others help, here my current situation that works (more or less):
- I have defined the
Gemfile
like defined in the question. - Therefore I had to ensure that the html5-boilerplate is not used in production mode. I have commented out parts of the html code that I do not need. I use the html5-boilerplate templates (mostly), and the application is on my local PC only, so the performance gain by using e.g. jquery from Google is not so relevant for me.
- Solved: The problems with the images in production mode (see one problem I could not solve currently at How do I use reference images in Sass when using Rails 3.1?, and the Rails 3.1.0 - asset:precompile fails when using asset_url() SASS function which is not solved in Rails 3.1.0)) where configuration problems due to the migration of Rails 3.0.x app to Rails 3.1.0. I solved it by copying a working configuration of a new created app (mostly
production.rb
which contained the wrong entry).
I will not invest more time here, and wait for updates for Rails 3.1.1 and html5-boilerplate.
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:
- I started with a new application and followed there the recipe "Setup html5-boilerplate with Rails 3.1".
- When I started the application (in development mode), it worked nicely.
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'
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.
精彩评论