Rails验证错误消息显示错误消息和数组

che*_*ell 1 ruby-on-rails ruby-on-rails-3 railstutorial.org

我正在完成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 %>
Run Code Online (Sandbox Code Playgroud)

我不仅获得了验证消息,而且还显示了实际的数组:

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)"]**
Run Code Online (Sandbox Code Playgroud)

对于我的生活,我无法弄清楚为什么.任何人都知道如何阻止这种显示?

提前致谢.

这是Rails3.0.7 Ruby 1.9.2 OSX10.6

Mik*_*kin 38

  <%= @user.errors.full_messages.each do |message| %>
       <li><%= message %></li>
Run Code Online (Sandbox Code Playgroud)

您使用此行<%= @user.errors.full_messages.each do |message| %>删除打印数组 =.