【问题标题】:Haml if else nestingHaml if else 嵌套
【发布时间】:2010-11-05 19:37:40
【问题描述】:

如何在不重复 .text.error 和 .text 之后的代码的情况下做到这一点?


     -if f.object.errors.any?
      .text.error 
        = f.label :email 
        = f.text_field :email
        %p#foo= "Escriba el e-mail"
        = render 'shared/error_messages', :object => f.object, :param => :email
    -else
      .text
        = f.label :email 
        = f.text_field :email
        %p#foo= "Escriba el e-mail"
        = render 'shared/error_messages', :object => f.object, :param => :email

    -if f.object.errors.any?
      .text.error
        = f.label :password
        = f.password_field :password
        = render 'shared/error_messages', :object => f.object, :param => :password
    -else
      .text.error
        = f.label :password
        = f.password_field :password
        = render 'shared/error_messages', :object => f.object, :param => :password   

【问题讨论】:

    标签: ruby-on-rails haml


    【解决方案1】:

    试试

    -["email", "password"].each do |param|
      .text{:class => f.object.errors.any? ? "error" : nil}
        = f.label param.to_sym 
        = f.text_field param.to_sym
        %p#foo= "Escriba el #{param}"
        = render 'shared/error_messages', :object => f.object, :param => param.to_sym
    

    【讨论】:

      猜你喜欢
      • 2010-12-17
      • 1970-01-01
      • 2012-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-18
      • 2015-06-04
      • 1970-01-01
      相关资源
      最近更新 更多