Ruby on rails and HAML - Print a hash with background color

1.5k views Asked by At

I have a Hash. my_hash = { "name": "aaa", "age":"28 [previous value: 27]"} I found the difference between two hashes and stored it in the above format. Now I need to print the Hash like this:

name aaa

age 28 [previous value: 27]

But I want the background of the line containing the age value(ie the value which contains the term "previous value") highlighted in green. Could anyone help me with this?

1

There are 1 answers

2
Mac On BEST ANSWER

You could do something like:

- my_hash.keys.each do |key|
  %p= key
  %p.highlighted-hash= my_hash[key]

And then you just need to add highlighted-hash to your stylesheet

.highlighted-hash {
  background-color: #00FF00;
}

#00FF00 is a hex value for green - you could change that up, obviously.

Or I suppose you could put the style inline:

- my_hash.keys.each do |key|
  %p= key
  %p{ style: 'background-color: #00FF00;' }
    my_hash[key]

But I would prefer something more like the first.