开发者

Haml if else nesting

开发者 https://www.devze.com 2023-01-24 05:06 出处:网络
How can you do this without repeating the code after the .text.error and .text ? -if f.object.errors.any?

How can you do this without repeating the code after the .text.error and .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.erro开发者_JAVA百科r
        = 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   


Try

-["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
0

精彩评论

暂无评论...
验证码 换一张
取 消