Skip to content

Instantly share code, notes, and snippets.

@manuelmeurer
Last active Nov 15, 2016
Embed
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 = Sass::Engine.new(scss, Compass.sass_engine_options.merge(syntax: :scss)).render
end
end
%style{ type: 'text/css' }
= css.chomp.html_safe
div[data-id="<%= foo %>"] {
display: none;
}
@benjamincanac
Copy link

benjamincanac commented Sep 9, 2013

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

Any idea ?

Thanks.

@yangbohr
Copy link

yangbohr commented Sep 26, 2013

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

@manuelmeurer
Copy link
Author

manuelmeurer commented Oct 5, 2013

@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";

@marat-chardymov
Copy link

marat-chardymov commented Nov 15, 2016

@manuelmeurer it works, thanks you!

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