# How can I remove messages from Errors object?

**URL:** <https://www.ruby-forum.com/t/how-can-i-remove-messages-from-errors-object/148042>\
**Category:** Rails\
**Created:** [September 8, 2008, 4:38pm UTC](https://www.ruby-forum.com/t/how-can-i-remove-messages-from-errors-object/148042 "2008-09-08T16:38:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![charlesr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/54ee81/32.png) [@charlesr](https://www.ruby-forum.com/u/charlesr)\
**Post date:** [September 8, 2008, 4:38pm UTC](https://www.ruby-forum.com/t/how-can-i-remove-messages-from-errors-object/148042/1 "2008-09-08T16:38:32Z")

</div>

I’m trying to handle complex form (nested forms) validation. (Using  
this link as [#75 Complex Forms Part 3 - RailsCasts](http://railscasts.com/episodes/75-complex-forms-part-3) as  
how I’m setting up the complex forms.)

Things are working ok, except that I’m getting a few extra messages to  
the base that I don’t want once the children forms are validated. For  
example if dealing with a Project mode and Task models as children…  
I’ll end up with an extra " Tasks is invalid" message for every Task  
that is invalid, which doesn’t look good considering the task  
validation messages are also showing up.

What I’d like to do is to be able to remove the extra “Tasks is  
invalid” messages that show up in my “after\_validation” method (unless  
someone can recommend a better thing to do?)

The problem is I can’t figure out how to remove messages from the  
Errors object?

def after\_validation  
errors.each do |field,message|  
if field == “tasks”  
#errors \>\> field ?Is there a way I can remove the message?  
end  
end  
end

---

<div class="post-metadata">

**Author:** ![charlesr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/54ee81/32.png) [@charlesr](https://www.ruby-forum.com/u/charlesr)\
**Post date:** [September 8, 2008, 11:00pm UTC](https://www.ruby-forum.com/t/how-can-i-remove-messages-from-errors-object/148042/2 "2008-09-08T23:00:46Z")

</div>

A colleague of mine dealt w/ something like this awhile ago. He removed  
all  
error messages for tasks and added a custom one that more clearly  
communicated the situation to the user. He said that you can treat the  
errors object as an array, so see the docs for Array#delete to delete  
all of  
the error messages for tasks.

Regards,  
Craig

---

<div class="post-metadata">

**Author:** ![charlesr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/54ee81/32.png) [@charlesr](https://www.ruby-forum.com/u/charlesr)\
**Post date:** [September 9, 2008, 1:22am UTC](https://www.ruby-forum.com/t/how-can-i-remove-messages-from-errors-object/148042/3 "2008-09-09T01:22:03Z")

</div>

On Sep 8, 4:50 pm, “Craig D.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> A colleague of mine dealt w/ something like this awhile ago. He removed all  
> error messages for tasks and added a custom one that more clearly  
> communicated the situation to the user. He said that you can treat the  
> errors object as an array, so see the docs for Array#delete to delete all of  
> the error messages for tasks.

From my newbie understanding of the Errors class  
[http://api.rubyonrails.org/classes/ActiveRecord/Errors.html](http://api.rubyonrails.org/classes/ActiveRecord/Errors.html) it’s not  
really an array, but of course probably is backed by one internally.  
Looks like someone put in a patch, although when I used edge rails I  
didn’t see it, so I just manually added the delete method to the  
validations.rb as shown in the dif and it’s working nicely.

[http://dev.rubyonrails.org/ticket/8137](http://dev.rubyonrails.org/ticket/8137)

(Being new to rails, does that patch mean it should be in the edge  
branch? or does it just mean it’s a suggestion to add it?)
