如何将其转换为haml?
<div class="alert alert-<%= name == :notice ? "success" : "error" %>">
答案 0 :(得分:1)
%div{:class => "alert alert-#{name == :notice ? 'success' : 'error' }"}
或更干净:
- alert_type = name == :notice ? 'success' : 'error'
%div{ :class => "alert alert-#{alert_type}" }
答案 1 :(得分:1)
这样的东西?
.alert{ class: "alert-#{name == :notice ? 'success' : 'error' }" }
或许这看起来更整洁:
%div{ class: "alert alert-#{name == :notice ? 'success' : 'error' }" }