gpt4 book ai didi

ruby-on-rails - Haml if else 嵌套

转载 作者:行者123 更新时间:2023-12-04 06:15:19 25 4
gpt4 key购买 nike

如何在不重复 .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

最佳答案

尝试

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

关于ruby-on-rails - Haml if else 嵌套,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4109397/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com