Skip to content

Instantly share code, notes, and snippets.

@manuelmeurer
Last active November 15, 2016 16:06
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manuelmeurer/6399889 to your computer and use it in GitHub Desktop.
Save manuelmeurer/6399889 to your computer and use it in GitHub Desktop.
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

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

Any idea ?

Thanks.

@yangbohr
Copy link

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

@manuelmeurer
Copy link
Author

@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

@manuelmeurer it works, thanks you!

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