Skip to content

config.sass options can't be set in production #3513

dmitriy-kiriyenko opened this Issue Nov 4, 2011 · 7 comments

5 participants


Hi all.

Default generated Rails application includes assets related gems in group :assets and requires them the following way:

Bundler.require(*Rails.groups(:assets => %w(development test)))

which means only require asset gems in non-development and non-test environment. So these gems should only be loaded during assets:precompile and not during rails server start in production environment.

However, the official sass-rails gem suggests us configure sass options via config.sass. So I'm supposed to add to my config/environments/production.rb something like:

config.sass.line_comments = false

if, say, I want do disable line comments, which are enabled by default. I'm aware of assets.compress option, which also allows me to remove comments, but what if I do not want to compress? Or let's say I want to configure some other sass option.

The problem is that while it works during assets:precompile it fails during server start in production mode with message undefined method 'sass' for Rails::Application::Configuration.

Not sure how this problem should be properly eliminated. I used a temporary workaround:

config.sass.line_comments = false if config.respond_to? :sass

but I believe something should be done about this. What do you think?

One solution could be defining method_missing on Rails::Application::Configuration in a way that if it's not setter, not bang and not predicate it would call appropriate setter with and return that object. This will eliminate the current problem and will also greatly simplify adding own nested configuration variables to rails configuration. If it's ok, I could provide a patch with this.

Or maybe it should be fixed within sass-rails? /cc @chriseppstein, @guilleiguaran


Doesn't require 'sass-rails' before the statement fix the issue?


The whole point about this group :assets is that I don't require asset gems in production environment. In fact, it would be even better if they even not existed in load path, when they are not required by Bundler.

Requiring these gems is just the same as not putting them into this group and doesn't look like a solution.

Ruby on Rails member

Sorry but I don't see a proper way to fix this in Rails, the unique fix for the error that I can imagine is add

@sass =

to railties/lib/rails/application/configuration.rb, but I don't think this is the proper solution.

Ruby on Rails member

Sorry, there isn't a good solution for this case, I suggest you use the workaround that you mentioned in your first message.


Using Rails 4.1 and after looking and looking (and possibly misreading the documentation) I got this to work by adding the following to /config/environments/development.rd & production.rb

config.sass.preferred_syntax = :scss = :compact
config.sass.line_comments = false

Style can be set to :nested, :expanded, :compact, :compressed.
You can see the different options here:

Also, make sure to restart your server to see the compiled version change

Hope this helps someone.

Ruby on Rails member

@benjordan in theory that's documented here:

Where were you looking? Maybe we need to cross-reference that from some other places?


I hope I do not come across as dumb or a jerk. But since you asked, here is how I think I missed it. It was the following sentence that eluded me:

To configure Sass via Rails set use config.sass in your application and/or environment files to set configuration properties that will be passed to Sass.

It took me a lot of reading to know exactly what file I needed to put the comments in even though it was stated there (and even though my first language IS English). In the last year, as I've been learning rails, I have grown used to seeing file names of the files in question listed out. That is more than likely why that escaped me. I found others asking similar questions on StackOverflow, etc, so came back here. For me, adding in something like the following would have helped me.

/config/application.rb or /config/enviromnments/#environment_name#.rb

config.sass.preferred_syntax = :scss = :compact
config.sass.line_comments = false

Options for style can be set to :nested, :expanded, :compact, :compressed

Hope that is helpful and not just an edge case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.