问题:
If post.published?
如果post.published?
.post
/ Post stuff
Otherwise除此以外
.post.gray
/ Post stuff
I've implemented this with rails helper and it seems ugly.我已经用 rails helper 实现了这个,它看起来很难看。
= content_tag :div, :class => "post" + (" gray" unless post.published?).to_s do
/ Post stuff
Second variant:第二个变体:
= content_tag :div, :class => "post" + (post.published? ? "" : " gray") do
/ Post stuff
Is there a more simple and haml-specific way?有没有更简单和特定于haml的方法?
UPD.更新。 Haml-specific, but still not simple:特定于 Haml,但仍然不简单:
%div{:class => "post" + (" gray" unless post.published?).to_s}
/ Post stuff
解决方案:
参考一: https://en.stackoom.com/question/EUQa参考二: https://stackoom.com/question/EUQa