1

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

2
  • My bad I used <%[email protected]_messages.each do |message|%> instead of <% @user.errors.full_messages.each do |message| Commented Jun 9, 2011 at 7:53
  • Post your comment in an answer and then accept it so the question shows as answered Commented Jun 9, 2011 at 9:01

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

-17

My bad I used

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

instead of

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

3 Comments

Which is what @Mikhail said. You might want to delete this and select his answer as correct.
Don't mind me... Just copying the right answer so I can accept it myself.
actually he figured it out in the comments before Mikhail

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.