# proper use of validates\_associated

**URL:** <https://discuss.rubyonrails.org/t/proper-use-of-validates-associated/999>\
**Category:** rubyonrails-talk\
**Created:** [September 3, 2006, 12:15pm UTC](https://discuss.rubyonrails.org/t/proper-use-of-validates-associated/999 "2006-09-03T12:15:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Serge\_Sozonoff](https://avatars.discourse-cdn.com/v4/letter/s/7cd45c/32.png) [@Serge\_Sozonoff](https://discuss.rubyonrails.org/u/Serge_Sozonoff)\
**Post date:** [September 3, 2006, 12:15pm UTC](https://discuss.rubyonrails.org/t/proper-use-of-validates-associated/999/1 "2006-09-03T12:15:04Z")

</div>

Hi All,

Is anyone using validates\_associated in a productive manner? What I mean is that I have not figured out how validates\_associated is actually supposed to make life easier.

I have been playing with this a little but have not gotten much out if it. For example I have a Person model and an Activation model. In the Person model I have defined validates\_associated :activations (Person has a 1..n with Activation)

When I do this for example after attempting person.save

\<%= error\_messages\_for 'person' %\>

and there is something invalid in an Activation instance associated with the person I simply get an error message (actually I get it twice, not sure why yet) stating that "Activations is invalid" rather than the specific error for the attribute which failed validation in the Activation instance. This is not very useful.

Alternatively I can of course validate the person instance and activation instance independantly and then dig out the error\_messages\_for for each instance but this is a little redundant.

Anyone have any good example or some good reading which discusses validates\_associated in more detail?

Thanks, Serge

---

<div class="post-metadata">

**Author:** ![Alastair](https://avatars.discourse-cdn.com/v4/letter/a/74df32/32.png) [@Alastair](https://discuss.rubyonrails.org/u/Alastair)\
**Post date:** [September 3, 2006, 1:00pm UTC](https://discuss.rubyonrails.org/t/proper-use-of-validates-associated/999/2 "2006-09-03T13:00:35Z")

</div>

I'm doing something very similar and am using this:

[http://railtie.net/articles/2006/01/26/enhancing\_rails\_errors](http://railtie.net/articles/2006/01/26/enhancing_rails_errors)

to report errors in a single error\_messages\_for report. However, it is still showing "ModelName is invalid" as well as the other error messages, which while not ideal will have to do at the moment!

---

<div class="post-metadata">

**Author:** ![Michael\_Schuerig1](https://avatars.discourse-cdn.com/v4/letter/m/ccd318/32.png) [@Michael\_Schuerig1](https://discuss.rubyonrails.org/u/Michael_Schuerig1)\
**Post date:** [September 11, 2006, 4:32pm UTC](https://discuss.rubyonrails.org/t/proper-use-of-validates-associated/999/3 "2006-09-11T16:32:51Z")

</div>

See ActiveRecord::Associations#add\_multiple\_associated\_save\_callbacks This method adds validations for all associated objects. If you add your own validation with validates\_associated you get double validation -- and double error messages -- for the same thing.

I only found out today myself.

Michael
