如何在不重复.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
答案 0 :(得分:5)
尝试
-["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