Haml: If statement inside attribute declaration
问题 I'm trying to put a conditional for a style attribute. According to this answer something like this should be possible: .hello{:style => (true ? 'color: green' : 'color: red;')} But for me the style attribute doesn't get outputted at all. Did things change in Haml? I rather not create a helper for such simple logic. 回答1: I would take the easy route out and add a line: - color = true ? 'color: green' : 'color: red;' .hello{:style => color} The even easier way is to add a further class and