[ACCEPTED]-Conditional class in HAML-haml

Accepted answer
Score: 25

Try this

%tr{ :class => ("overdue" if ap.overdue?) }

0

Score: 4

HAML has a nice built in way to handle this:

%tr{ class: [ap.overdue? && 'overdue'] }

The 4 way that this works is that the conditional 3 gets evaluated and if true, the string gets 2 included in the classes, if not it won't 1 be included.

More Related questions