Haml: How to add classes dynamically to an element?
I have a <tr>
element in my view, and I want to add classes dynamically开发者_Go百科 on this element depending on an association between two models (many to many between company and packaging).
The result should looks like
<tr class="pck1 pck3 pck5">
where pck1
, pck3
and pck5
are packagings associated with a company.
or simply:
%tr{ :class => classes }
Say you have an array classes = ['pck1', 'pck3', 'pck5']
with the classes you want your tr
to have.
Just type something like:
%tr{:class => classes.join(' ')}
精彩评论