let an imported partial with .erb extension be processed by sprockets #94

jfirebaugh opened this Issue Feb 16, 2012 · 9 comments

7 participants


I have a white-labeled service where customers can select a color scheme to match their branding. I'm using locales to hold the color information, and I want to use the colors in my stylesheets. (It's very similar to this SO question.) I'll use a custom assets:precompile task to statically compile the stylesheet assets for each locale. With that in mind, I'd like to do something like this:

In application.css.scss:

@import "colors";
#header { background-color: $header-color; }

In _colors.scss.erb:

$header-color: <%= I18n.t('header_color') %>;

But this doesn't work.

First off, Sass::Rails::Importer assumes that a file that has .scss anywhere in the name is an SCSS file (even if it's not the ending extension), so my _colors.scss.erb doesn't get processed by Sprockets at all.

Even if this bug were fixed, and _colors.scss.erb was sent through @resolver.process instead, the result is not what I want, because it's been run through both ERB and SCSS processing. Since the file is just a set of SCSS variable declarations, the result is empty. What I really want is for just ERB processing to take place, and then the result of that imported.

I've found a workaround -- name the file _colors.css.erb, but it would be awesome if this would just work.


Will happily accept a patch for this.


+1, having the same problem


sprockets-sass claims to have this feature, maybe we can port the code from there.


I think I have a fix for this, but I can't seem to get all of the tests to pass (before making any changes). Commenting out "sprockets-rails" in the gemfile helped (there is already a version specified in the gemspec?) but after that I am stuck. Does anyone have any advice on properly setting up an environment to run the test suite? Here is the output when I run 'bundle exec rake test': https://gist.github.com/3824627


I added a gem for the monkey-patch i created: http://rubygems.org/gems/sass_rails_patch


Hi! I'm having the same issue.

I want to create replicate the sass variables in javascript as well.
So I'm trying to create constants in ruby that are then generated for sass and javascript. For that I need to call ruby inside a sass file.

Did anyone solve this?


Hi Luis, the patch I created above, at least at time of writing, fixed this for me.


The patch isn't working for me anymore. When I start the rails dev server I get the error:

/usr/local/rvm/gems/ruby-1.9.3-p194/gems/sass_rails_patch-0.0.1/lib/sass_rails_patch.rb:1:in `<top (required)>': uninitialized constant Sass (NameError)

Closing here. Follow #139 discussion.

@frodsan frodsan closed this Apr 30, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment