chell
chell

Reputation: 7866

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:  
        </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

Upvotes: 1

Views: 11647

Answers (2)

chell
chell

Reputation: 7866

My bad I used

<%[email protected]_messages.each do |message|%> 

instead of

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

Upvotes: -17

Mikhail Nikalyukin
Mikhail Nikalyukin

Reputation: 11967

  <%= @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.

Upvotes: 39

Related Questions