serge-+Zb6sA+pqMZWk0Htik3J/w@public.gmane.org
2006-Sep-03 12:15 UTC
proper use of validates_associated
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
I''m doing something very similar and am using this: 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! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On Sunday 03 September 2006 14:15, serge-+Zb6sA+pqMZWk0Htik3J/w@public.gmane.org wrote:> 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.On Sunday 03 September 2006 15:00, Alastair Moore wrote:> I''m doing something very similar and am using this: > > 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!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 -- Michael Schuerig mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org http://www.schuerig.de/michael/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---