Today I Learned

hashrocket A Hashrocket project

Conditional Class Selectors in Haml

You can assign a class selector to a tag in HAML like so:

You can conditionally assign a class selector in a concise manner like so:

%div{ class: ( "active" if ) }

You can do multiple conditional class selectors with array syntax:

%div{ class: [ ("active" if, ("highlight" if @thing.important?) ] }


See More #rails TILs
Looking for help? Hashrocket has been an industry leader in Ruby on Rails since 2008. Rails is a core skill for each developer at Hashrocket, and we'd love to take a look at your project. Contact us and find out how we can help you.