如果 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
有没有更简单,更专业的方法?
UPD 哈姆尔特有,但还不简单:
%div{:class => "post" + (" gray" unless post.published?).to_s}
/ Post stuff