Removing Specific ActiveRecord Errors

Is there a way to remove a specific error or errors on a specific attribute? I see there is a object.errors.clear, but that clears all the errors associated with the object. I would like to do something like object.errors.clear('email'), where any errors associated with the email attribute are cleared out.

Thanks, Tom

dear sender, i�m out of the office until may 29th. your email will not be forwarded. for urgent stuff please contact joern@fork.de kind regards, alexander

Tom, did you ever get a solution to this problem, or even a work around. I've got the same issue now.

Thanks in Advance Tom Styles

TomRossi7 wrote:

object.errors looks like a hash. Can you do a puts object.errors and post the result?

If it says :email => ‘foo’ somewhere, you should be able to do object.errors.clear :email

Thanks for the tip Commander. I figured it out.

I was needing to do a validates_associated but I didn't want the error message to appear in my view. My answer to this at the time was to remove the error message once the object had been validated.

However a much better way was to write my own validate statement

def validate   return false unless self.associated_object.valid? end

This way I'm checking that the associated object is valid without generating the errors in the first place.

I love the rails validates helpers so much that I forget I can do validation myself and get all the control I'll ever need.

Cheers Tom

Tom Styles wrote:

I was needing to do a validates_associated but I didn't want the error message to appear in my view. My answer to this at the time was to remove the error message once the object had been validated.

However a much better way was to write my own validate statement

def validate   return false unless self.associated_object.valid? end

This way I'm checking that the associated object is valid without generating the errors in the first place.

I love the rails validates helpers so much that I forget I can do validation myself and get all the control I'll ever need.

You can also use :message => nil option on the validates_associated statement.