Reputation: 7419
I have this html
<tr <% if ap.overdue? %>class = "overdue"<% end %> >
<td><%= ap.id %></td>
<td><%= link_to ap.affiliate.title, superadmin_affiliate_path(ap.affiliate) %></td>
</tr>
How do I code the equivalent in HAML?
In particular the first line, which assigns a class only if the if
condition is true.
Upvotes: 17
Views: 7982
Reputation: 2457
HAML has a nice built in way to handle this:
%tr{ class: [ap.overdue? && 'overdue'] }
The way that this works is that the conditional gets evaluated and if true, the string gets included in the classes, if not it won't be included.
Upvotes: 8