如何将此erb转换为haml?

时间:2012-09-19 20:32:34

标签: ruby-on-rails haml erb

如何将其转换为haml?

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

2 个答案:

答案 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' }" }