如果 post.published?
.post
/ Post stuff
除此以外
.post.gray
/ Post stuff
我已经用rails helper实现了它,这看起来很丑。
= content_tag :div, :class => "post" + (" gray" unless post.published?).to_s do
/ Post stuff
第二个变体:
= content_tag :div, :class => "post" + (post.published? ? "" : " gray") do
/ Post stuff
有没有更简单且特定于haml的方法?
UPD。Haml特有的,但仍然不简单:
%div{:class => "post" + (" gray" unless post.published?).to_s}
/ Post stuff