November 22, 2011

Rails Append class if condition is true in Haml

.post{ :class => ('gray' unless post.published?) }

HAMLである条件がtrueの時だけあるclassをタグに追加したい場合。

Share on Twitter Share the post
Qihuan Piao

Qihuan Piao

(aka kinopyo) is Chinese based in Tokyo. Software writer. He shares stories inspired him in this blog. His infamous line - "I feel calm when I kill those monsters, or people (in game)" shocks his friends deeply.

He also writes in Japanese and Chinese.