0

I dont know but in my view are appears my message but before appear the name of model, in my view i write this:

<% @cost.errors.messages.each { |m| %>
<%= m %> 
<%  } if @cost.errors.count > 0 %>

in my model write this:

   validates_length_of :types,:minimum => 3,:message => "Precisa ter no minimo 3 caracteres."

but when the rails detect errors the message appear this:

typesPrecisa ter no minimo 3 caracteres.

Because what apeear the name of model, types in my view please

1
  • try @cost.errors.full_message (or full_messages) Commented Feb 12, 2013 at 16:31

1 Answer 1

1

Try this:

  <% @cost.errors.full_messages.each do |m| %>
      <%= m %> 
  <%  end if @cost.errors.present? %>
Sign up to request clarification or add additional context in comments.

4 Comments

You should test @cost.errors.present? instead of counting them and compare it to zero ([].present? #=> false)
@MrYoshiji yup, you can do that :)
Im use this but the name of model continuous appear how im my question please what is wrong please
@overallduka It will not show name of the model bcz @cost.errors.full_messages will return an array. You can check it on Rails console

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.