How to insert instance variable as css rule in Rails?

Tags: css,ruby-on-rails,ruby

Problem :

Let's say I've got AR class:

  store :skin_properties, accessors: [

Which save values in this way:

{"background_color"=>"#f2f2f2", "font_size"=>"20px", "font_family"=>"Verdana", "color"=>"#000000"}

How can I insert it in edit.haml file as inline css?

I tried something like this, but it's not working ...

    -@user.skin_properties.each_with_index do |(k,v)|

Solution :

Thanks everybody, came up with something like this:

- css = {|k,v| "#{k.dasherize}: #{v};" }.join("\n")
%style== body { #{css} }

    CSS Howto..

    Looping through my table, how do I know if the checkbox is checked?

    How do I give a JavaFX TextField a Swing-style lowered bevel border?

    How can I reload css styles when change windows width?

    How do I set the table row heights to minimum except last row?

    How to horizontally align to “block” divs inside a div?

    How can I attach an object to a fixed location on an image?

    css show separator icon for icons

    How to denote common class names with slight numeral changes into one - CSS shorthand?

    When I click on each button its shows me the same content of the first button

    how to wrap a text around a image?

    How can I add some css to center certain divs if they are using the same css style? [duplicate]

    How to create a dropdown that is open by default and with custom scrollbars ( see pic from wireframes) in HTML [closed]

    How to detect when one or more JS/CSS library fail to load (e.g. CDN)?

    How I can add td to css style for inputs and its label?

    How to check if a css/js resource is included in head

    CSS - How to resize texboxes with background image when browser is resized?

    CSS: How to prevent div from overlapping parent height or parent border

    How can I make a background image of a site start off fitting to screen and then zoomable?

    How to have jquery add a panel inside a panel in Bootstrap v3

    How to disable Javascript/CSS minification in ASP.NET MVC 4 Beta

    How to over-ride img-width from bootstrap? Set css rule to null?

    How do you use CSS Selectors to select multiple elements? [duplicate]

    wordpress submenu css show on parent active and child active

    How to serve css files in djangos's flatpages?

    with Box-Shadow = 6 cicles. How it works?

    How do I use a variable to get CSS info on an element?

    How to add javascript to an image from the content_wrapper in the css stylesheet

    How are CSS properties implemented by different browsers? [closed]

    How to enable links if a parent element uses a fullscreen pseudo-element?

    Are where any examples available on how to use postcss-modules instead of css-modules?