开发者

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(' ')}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜