Ruby on Rails: Is there a way to tell what fields failed validation in ActiveRecord?

Posted by randombits on Stack Overflow See other posts from Stack Overflow or by randombits
Published on 2010-04-25T00:09:27Z Indexed on 2010/04/25 0:13 UTC
Read the original article Hit count: 182

Filed under:
|
|

I'm attempting to create an XML builder file that tells a user to know exactly what fields failed validation in the output. I also want to display their input back to them, so that requires me figuring out which fields failed validation. Meaning if someone fails on creating a new user resource, I want to display XML that's meaningful (Besides a meaningful HTTP status number) such as:

<errors>
    <user>
        <email>bad@email: Invalid email format</email>
    </user>
<errors>

The above is tough to do in an XML builder file without knowing what field failed. And if I just iterate over error messages, I won't know how to prob my @user object to get the value that the user supplied.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby