Append class if condition is true in Haml

后端 未结 5 1475
温柔的废话
温柔的废话 2020-11-30 17:50

If post.published?

.post
  / Post stuff

Otherwise

.post.gray
  / Post stuff

I\'ve implemente

5条回答
  •  一个人的身影
    2020-11-30 18:29

    - classes = ["post", ("gray" unless post.published?)]
    = content_tag :div, class: classes do
      /Post stuff
    

    def post_tag post, &block
      classes = ["post", ("gray" unless post.published?)]
      content_tag :div, class: classes, &block
    end
    
    = post_tag post
      /Post stuff
    

提交回复
热议问题