开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜