Я получаю повторяющиеся сообщения об ошибках вокруг полей формы - одно для метки и одно для поля. Я понятия не имею, почему ярлыку присваивается сообщение об ошибке. Я включил весь связанный код, который я знаю. Пожалуйста, помогите, если можете, спасибо!
версия рельсов 3.0.11
сгенерированный HTML:
<div class="field">
<div class="field_with_errors"><label for="customer_email">Email</label><br /><span class="validation-error">
has already been taken</span></div><br />
<div class="field_with_errors"><input id="customer_email" name="customer[email]" size="30" type="text" value="asdrummo@gmail.com" /><br /><span class="validation-error">
has already been taken</span></div>
</div>
Пароль
в моем приложении. Rb:
config.action_view.field_error_proc = Proc.new do |html_tag, instance|
if instance.error_message.kind_of?(Array)
%(<div class="field_with_errors">#{html_tag}<br /><span class="validation-error">
#{instance.error_message.join(',')}</span></div>).html_safe
else
%(<div class="field_with_errors">#{html_tag}<br /><span class="validation-error">
#{instance.error_message}</span></div>).html_safe
end
end
моя форма выглядит так:
<%= form_for(@customer, :url => {:action => 'save_customer'}) do |f| %>
<% if @customer.errors.any? %>
<%= error_messages_for(@customer)%>
<% end %>
<div class="field">
<%= f.label :email %><br />
<%= f.text_field :email %>
</div>
<div class="field">
<%= f.label :password %><br />
<%= f.password_field :password %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
error_messages_for (объект):
def error_messages_for( object )
render(:partial => 'shared/error_messages', :locals => {:object => object})
end
разделяемые / error_messages:
<div class="error">Please correct the <%= pluralize(@customer.errors.count, "error") %> below and resubmit.</div>
и, наконец, мои проверки:
validates :email, :presence => true, :length => {:maximum => 100 }, :format => EMAIL_REGEX, :confirmation => true, :uniqueness => true
validates :password, :on => :update_password, :presence => true, :confirmation => true, :length => { :minimum => 5}
UPDATE
с кодом, удаленным из application.rb, я все еще получаю следующее (пример ошибки проверки электронной почты):
<div class="field">
<div class="field_with_errors"><label for="customer_email">Email</label></div><br />
<div class="field_with_errors"><input id="customer_email" name="customer[email]" size="30" type="text" value="asdrummo@gmail.com" /></div>
</div>