Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails表单字段重复错误消息_Ruby On Rails_Ruby On Rails 3_Validation - Fatal编程技术网

Ruby on rails Rails表单字段重复错误消息

Ruby on rails Rails表单字段重复错误消息,ruby-on-rails,ruby-on-rails-3,validation,Ruby On Rails,Ruby On Rails 3,Validation,我在表单字段周围收到重复的错误消息-一条用于标签,另一条用于字段。我不知道为什么标签会被分配错误消息。我已经包括了我所知道的所有相关代码。如果可以,请帮忙,谢谢! rails版本3.0.11 生成的html: <div class="field"> <div class="field_with_errors"><label for="customer_email">Email</label><br /><span class="v

我在表单字段周围收到重复的错误消息-一条用于标签,另一条用于字段。我不知道为什么标签会被分配错误消息。我已经包括了我所知道的所有相关代码。如果可以,请帮忙,谢谢! rails版本3.0.11

生成的html:

<div class="field">
<div class="field_with_errors"><label for="customer_email">Email</label><br /><span class="validation-error">&nbsp;
      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">&nbsp;
      has already been taken</span></div>
</div>
共享/错误消息:

<div class="error">Please correct the <%= pluralize(@customer.errors.count, "error") %> below and resubmit.</div>
更新

从application.rb中删除代码后,我仍然得到以下结果(电子邮件验证错误的示例):


电子邮件

为什么说有一条消息“针对标签”和一条消息“针对字段”?警告以“
开头显示,因此它们出现在元素下,并带有错误-从HTML中可以看到,错误显示在标签下和字段下。不知道为什么。请注意,您运行的是旧版本的Rails 3.0,最新的补丁版本是3.0.11,并且包含重要的安全修补程序,因此您应该更新Rails版本。感谢您提供的信息-我已经更新到Rails 3.0.11。问题仍然存在。我可能在去年夏天修改了一些代码,以便将错误类分配给标签(?)我确实安装了作为插件/gem的动态表单,但我已经卸载并删除了。有什么想法吗?我发现临时答案是添加一个子句,如果将错误分配给标签标记,则不包括实例:if html_tag=~/^
<%= 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 %>
def error_messages_for( object )
    render(:partial => 'shared/error_messages', :locals => {:object => object})
end
<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}
<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>