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..

    How can I make my form field have a background image?

    CSS: How to set up gradient background cross browser (only missing IE8 and IE9)

    How to reference embedded images from CSS?

    How do I handle setting multiple styles (due to vendor prefixes) in CSS with Javascript?

    How to apply css on every 2nd child using nth-child() with jquery

    how to align the content to center of page using css

    How to repeat a menu without using iFrames or PHP in simple HTML/CSS or XML?

    How to align radio buttons with labels in one line? [duplicate]

    How to get css button to stay active after it has been clicked?

    In CSS/JS, how to word-wrap at every nth word?

    How to make this kind of border css? [closed]

    How to get MathJax's HTML output just like

    How to stop text in div pushing other divs down the page?

    CSS: how to apply margin to a container with floats?

    How achieve rounded shadow behide a rounded element using css3

    How can I make a similar shape to a parallelogram in css?

    Messed up slides in custom minimal JS/CSS slideshow

    How to fix css and jQuery slide show? [closed]

    How to center a DIV with CSS?

    In IE6, how to float item to right without clearing it?

    how to add border to image css on blogger

    How to create spoiler text?

    CSS position: absolute - understanding how to center text inside a div box

    How to modify css class of container for specific element ID

    How to remove dot '.' from CSS list-style:decimal [duplicate]

    How to customize post excerpt css

    overlaying divs with onclick in slideshow -> onclick doesnt change

    How to change default theme color teal to blue without using custom CSS in materilaize

    How to distribute DIVS evenly (horizontal and vertical) that floats with each other?

    How to make AngularJS Materials drop down menues more visable?