开发者

Rails validation error messages displays the error messages and array

I am working through the Ruby-on-Rails3 Tutorial Chapter 8.

I have created a form that a user submits to sign up to a site.

The validations are set in the model. They have been tested and are working.

The problem is that when I display the validation error messages doing the following:

    <% if @user.errors.any? %>
    <div id="error_explanation">
        <h2>
            <%= pluralize(@user.errors.count, "error")%>
            prohibited this user from being saved:  
    开发者_StackOverflow中文版    </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 %>

I not only get the validation messages but the actual array is shown as well:

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)"]**

For the life of me I can't figure out why. Anyone know how to stop this from displaying?

Thanks in advance.

This is Rails3.0.7 Ruby 1.9.2 OSX10.6


  <%= @user.errors.full_messages.each do |message| %>
       <li><%= message %></li>

You printing array with this line <%= @user.errors.full_messages.each do |message| %> delete = from it.


My bad I used

<%=@user.errors.full_messages.each do |message|%> 

instead of

<% @user.errors.full_messages.each do |message|
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜