开发者

Haml: How to add classes dynamically to an element?

开发者 https://www.devze.com 2023-01-17 08:23 出处:网络
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).

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

精彩评论

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