我正在阅读 Ruby-on-Rails3 教程第 8 章。
我创建了一个用户提交以注册网站的表单。
验证在模型中设置。他们已经过测试并且正在工作。
问题是当我显示验证错误消息时,执行以下操作:
<% if @user.errors.any? %>
<div id="error_explanation">
<h2>
<%= pluralize(@user.errors.count, "error")%>
prohibited this user from being saved:
</h2>
<p>There were problems with the following fields:</p>
<ul>
<%= @user.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
我不仅得到了验证消息,而且还显示了实际的数组:
2 errors prohibited this user from being saved:
There were problems with the following fields:
Password can't be blank
Password is too short (minimum is 6 characters)
**["Password can't be blank", "Password is too short (minimum is 6 characters)"]**
对于我的生活,我无法弄清楚为什么。有谁知道如何阻止它显示?
提前致谢。
这是 Rails3.0.7 Ruby 1.9.2 OSX10.6