Include? condition in haml view
I try to make something like this in haml view :
%li{:class => @taxon and ([@taxon] + @taxon.ancestors).include?(taxon)开发者_运维知识库 : "current"}
what the correct syntax ?
I'm guessing the value of @taxon is the class name? If so this should work for you.
- taxon_class = (@taxon && ([@taxon] + @taxon.ancestors).include?(taxon)) ? @taxon : "current"
%li{:class => taxon_class}
I always find it easier to do the ruby logic outside of the haml {} brackets.
精彩评论