-
-
Save mattbrictson/1685685 to your computer and use it in GitHub Desktop.
# Precompile *all* assets, except those that start with underscore | |
config.assets.precompile << /(^[^_\/]|\/[^_])[^\/]*$/ |
/* | |
* application.scss | |
* | |
* Important! Do *not* use Sprockets "require" syntax. | |
* Use @import to include other stylesheets and Compass mixins. | |
*/ | |
// Include some nice mixins | |
@import "compass/css3"; | |
@import "sassy-buttons"; | |
// Example: import partial stylesheet named "_users.scss" | |
@import "users"; |
# config/compass.rb | |
additional_import_paths = ["app/assets/stylesheets/basics", "app/assets/stylesheets/shared"] |
A ActionView::Template::Error occurred in sessions#new: | |
1024.css isn't precompiled | |
.bundle/bundle/gems/actionpack-3.2.0/lib/sprockets/helpers/rails_helper.rb:142:in `digest_for' |
.logo | |
{ | |
background: image-url("logo-small.png") no-repeat; | |
} |
group :assets do | |
gem 'compass-rails','~> 1.0.0.rc.2' | |
gem 'compass-colors' | |
gem 'sassy-buttons' | |
gem 'sass-rails', '~> 3.2.3' | |
# non-compass gems omitted for brevity | |
end |
$ bundle exec rake assets:precompile | |
/Users/mbrictson/.rbenv/versions/1.9.3-p0/bin/ruby script/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets | |
rake aborted! | |
Undefined variable: "$body-text-line-height". | |
(in /Users/mbrictson/Work/rails-project/app/assets/stylesheets/basics/_grid.scss) | |
Tasks: TOP => assets:precompile:primary | |
(See full trace by running task with --trace) | |
rake aborted! | |
Command failed with status (1): [/Users/mbrictson/.rbenv/versions/1.9.3-p0/...] | |
Tasks: TOP => assets:precompile | |
(See full trace by running task with --trace) |
. | |
├── Gemfile | |
├── app | |
│ └── assets | |
│ ├── images | |
│ │ └── logo-small.png | |
│ ├── javascripts | |
│ │ └── application.js | |
│ └── stylesheets | |
│ ├── _users.scss | |
│ └── application.scss | |
└── config | |
├── application.rb | |
└── compass.rb |
jwoodlee
commented
Feb 25, 2012
via email
I have a problem with running Compass according to the instructions on
http://blog.55minutes.com/2012/01/getting-compass-to-work-with-rails-31-and-32/
EDIT: The problem is caused by setting:
config.assets.compile = true
in config/environments/production.rb
When it is set to true
then Rails tries to compile missing assets on demand when running in production mode. To achieve that it needs Compass and other stuff, that is only available in development and test environments (as set in Gemfile
).
The problematic part of the mentioned entry is a note that one should avoid directly requiring compass in the Gemfile.
In my case putting only compass-rails in Gemfile causes Compass global constant to be invisible and causes errors to be thrown when in production mode. That's because the compass gem is not loaded. Here is the example error I got:
ActionView::Template::Error (File to import not found or unreadable: blueprint/reset.
Load path: Sass::Rails::Importer(/myapp/assets/stylesheets/print.css.scss)
(in /myapp/assets/stylesheets/print.css.scss)): […]
That's just the effect of my initializers/sass.rb
being unable to set proper paths.
My code for setting the paths for SASS is:
if Rails.application.config.respond_to?(:sass)
Rails.application.config.sass.tap do |sass|
sass.load_paths.tap do |load_paths|
load_paths << File.join(Rails.root, 'app', 'assets', 'stylesheets')
if Kernel.const_defined?( :Compass )
['compass','blueprint'].each do |compass_framework|
load_paths << Compass::Frameworks[compass_framework].stylesheets_directory
end
end
end
sass.line_comments = Rails.env.production? ? false : true
sass.preferred_syntax = :scss
end
end
Conclusion: either put compass-rails out of assets
group in Gemfile
or disable config.assets.compile
in config/environment/production.rb
.
@siefca, yes, the config.assets.compile=true
setting is problematic in production. Usually you will not want to do this. If you have good reason to set config.assets.compile=true
, then you will need to ensure the asset pipeline gems are loaded.
I actually describe this in detail in the following blog post (see the config.assets.compile section):
http://blog.55minutes.com/2012/02/untangling-the-rails-asset-pipeline-part-3-configuration/
@mbrictson: That;s true. I'm just using it as a workaround, since rake assets:precompile
takes sometimes up to 10 minutes with Sprockets and Compass.
Just a note, but in 'application.scss', @import "sassybuttons" should be @import "sassy-buttons" as per jhardy/Sassy-Buttons#14