0

我如何将其转换为haml?

<div class="alert alert-<%= name == :notice ? "success" : "error" %>">
4

2 回答 2

1
%div{:class => "alert alert-#{name == :notice ? 'success' : 'error' }"}

或者,更干净:

- alert_type = name == :notice ? 'success' : 'error'
%div{ :class => "alert alert-#{alert_type}" }
于 2012-09-19T20:34:31.747 回答
1

像这样的东西?

.alert{ class: "alert-#{name == :notice ? 'success' : 'error' }" }

或者这看起来更整洁:

%div{ class: "alert alert-#{name == :notice ? 'success' : 'error' }" }
于 2012-09-19T20:34:47.810 回答