Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional class in HAML

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.

like image 846
Marco Prins Avatar asked May 28 '14 10:05

Marco Prins


1 Answers

Try this

%tr{ :class => ("overdue" if ap.overdue?) }
like image 78
Rajdeep Singh Avatar answered Sep 27 '22 19:09

Rajdeep Singh