【问题标题】:How do I transform this erb to haml?我如何将这个erb转换为haml?
【发布时间】:2012-09-20 04:34:47
【问题描述】:

如何将其转换为haml?

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

【问题讨论】:

标签: ruby-on-rails haml erb


【解决方案1】:

这样的?

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

或者这看起来更整洁:

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

【讨论】:

    【解决方案2】:
    %div{:class => "alert alert-#{name == :notice ? 'success' : 'error' }"}
    

    或者,更简洁:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-16
      • 1970-01-01
      • 2015-09-10
      • 1970-01-01
      • 1970-01-01
      • 2012-10-06
      • 1970-01-01
      相关资源
      最近更新 更多