-1

我的 Sinatra 应用程序中有一个代码

    - if flash[:error]
      .alert.alert-error
        %button.close{:type =>" button", "data-dismiss"=>"alert"}x
        = flash[:error]
    - if flash[:warning]
      .alert.alert-warning
        %button.close{:type =>" button", "data-dismiss"=>"alert"}x
        = flash[:warning]
    - if flash[:info]
      .alert.alert-info
        %button.close{:type =>" button", "data-dismiss"=>"alert"}x
        = flash[:info]

有什么办法可以简单的吗?:type =>" button", "data-dismiss"=>"alert"特别是,有没有办法通过将它们存储为变量来摆脱重复的哈希初始化?

4

1 回答 1

1

尝试类似:

- flash.each do |type, message|
  .alert{ :class => "alert-#{type}" }
    %button.close{:type =>" button", "data-dismiss"=>"alert"}x
    = message
于 2012-12-31T09:14:21.363 回答