Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic class name in HAML

Tags:

erb

haml

Is there a better way to convert the following to HAML?

<% flash.each do |key, value| %>   <div class="flash <%= key %>"><%= value %></div> <% end %> 

Best I can do is:

  - flash.each do |key, value|     %div{:class => "flash " + key.to_s}= value 

But it seems awkward. And .flash#{ key}= value doesn't seem to be right?!?

like image 909
Meltemi Avatar asked Dec 09 '10 02:12

Meltemi


1 Answers

If you're looking for something every-so-slightly terser, you can do this now in haml:

- flash.each do |key, value|   .flash(class=key)= value 
like image 159
gunn Avatar answered Oct 05 '22 20:10

gunn