6

I've got following code in erb which works fine:

<div id='flash_<%= flash.keys.first.to_s %>'>
    <%=h    flash[flash.keys.first] %>
</div>

I want to convert it into haml:

#flash_#{flash.keys.first.to_s}
  =h flash[flash.keys.first]

But I receive error:

Illegal element: classes and ids must have values.

Which is strange as there IS value, 'flash_' part is always present, I get that error even when I do:

#flash_#{nil.object_id}

Apparently something wrong is with my Ruby interpolation in haml, but I can't get it right. According to documentation http://haml.info/docs/yardoc/file.REFERENCE.html#ruby_interpolation_ #{} is used to interpolate Ruby and it works in such case:

#flash_
  #{flash.keys.first.to_s}

but that's not what I want.

To sum up, I want to get the following output:

<div id="flash_foo"> blahblah </div>

but it can be also:

<div id="flash_"></div>

How to obtain that with haml?

lulalala
  • 17,572
  • 15
  • 110
  • 169
zrl3dx
  • 7,699
  • 3
  • 25
  • 35
  • Till you are comfortable with HAML use [this](http://html2haml.heroku.com/) converter – prem Apr 28 '13 at 15:41
  • @prem: thanks for that link, it will be very useful for me. – zrl3dx Apr 28 '13 at 16:14
  • possible duplicate of [How do I make dynamic ids in Haml?](http://stackoverflow.com/questions/2217583/how-do-i-make-dynamic-ids-in-haml) – lulalala Jan 20 '14 at 06:01

1 Answers1

12
%div{ :id => "flash_#{flash.keys.first}" }    
  =h flash[flash.keys.first]
Reuben Mallaby
  • 5,740
  • 4
  • 47
  • 45