How to convert this ERB code:
<div <%= 'class="highlight"' if job.done %>>
into Haml code?
%div{:class => ('hightlight' if job.done)}
I believe would also do the trick, and doesn't create class= '' if job.done == false, also looks more like your initial code
%div{class:job.done && "highlight"}
If you set an attribute to false
or nil
, Haml will omit the attribute altogether.
%div{job.done ? {:class => "highlight"} : {}}
%div{:class => job.done ? "highlight" : ""}