Skip to content

Instantly share code, notes, and snippets.

Last active November 15, 2016 16:06
What would you like to do?
Render dynamic CSS
class Display::WidgetsController < ApplicationController
def show
scss = render_to_string('show', locals: { foo: bar }, formats: :scss)
@css =, Compass.sass_engine_options.merge(syntax: :scss)).render
%style{ type: 'text/css' }
= css.chomp.html_safe
div[data-id="<%= foo %>"] {
display: none;
Copy link

This does not work for me with @import into the .scss.erb file.

Any idea ?


Copy link

you need set gems in assets group in Gemfile accessible under production environment

Copy link

@imports should work if you:

  • make sure you're importing a partial, i.e. the filename must be _base.css.scss, not base.css.scss
  • include the full filename except .scss in the import directive, i.e. @import "base.css";

Copy link

@manuelmeurer it works, thanks you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment