# Cleare errors on a given attribute

**URL:** <https://www.ruby-forum.com/t/cleare-errors-on-a-given-attribute/80657>\
**Category:** Ruby\
**Created:** [December 29, 2006, 6:05pm UTC](https://www.ruby-forum.com/t/cleare-errors-on-a-given-attribute/80657 "2006-12-29T18:05:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fedot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/82dd89/32.png) [@fedot](https://www.ruby-forum.com/u/fedot)\
**Post date:** [December 29, 2006, 6:05pm UTC](https://www.ruby-forum.com/t/cleare-errors-on-a-given-attribute/80657/1 "2006-12-29T18:05:24Z")

</div>

I’ve been studying Rails source code to figure out how to clear  
ActiveRecord errors for a given attribute name. It appears that there is  
no direct API to do that. The best workaround I found is this:

active\_record.errors.add(attribute\_name, “dummy”).clear

Basically, “add” returns an array of error messages for given attribute  
name, which I subsequently clear. Seems to work, but doesn’t feel  
“right”.

In case anyone wonders why in the world I needed such functionality,  
here is a brief explanation. I have an object with a has\_many  
association. If any of the children fail validation, the following error  
is displayed for the parent object: “(insert association name here) is  
invalid”. I do not find this particular error message to be very  
informative and instead would rather display exact children errors.  
Hence, I would like to make a sweep over parent object errors and remove  
any errors on associations after validation but before rendering.

If anyone has any better suggestions on better displaying children  
errors, I am all ears 🙂

Regards,  
Fyodor Golos

---

<div class="post-metadata">

**Author:** ![fedot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/82dd89/32.png) [@fedot](https://www.ruby-forum.com/u/fedot)\
**Post date:** [December 29, 2006, 6:09pm UTC](https://www.ruby-forum.com/t/cleare-errors-on-a-given-attribute/80657/2 "2006-12-29T18:09:09Z")

</div>

My bad. Wrong list. Reposted in “Ruby on Rails”
