問題:
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