I was just wondering where the "associated_records" comes from? Just tried your idea but got a:
"undefined local variable or method `associated_records'" Where did you put "valid_associated_records?" exactly? Is it just a method you call from within the model's "validate" function? thanks On Thu, Jul 31, 2008 at 3:50 AM, walker <[EMAIL PROTECTED]> wrote: > > I had to come up with a hack to get around this (duplicate and generic > validation error messages). I also wanted to include my specific error > messages from the child models. Basically, this is my custom > validator: > > #custom validator so i can make error messages appear the way i want > #(instead of validates_associated) > def valid_associated_records? > associated_records.each do |ar| > if(!ar.nil? && !ar.valid?) > #get rid of the default error message > errors.delete(:attribute_name) > > #take specific error messages from children, put them in this > model's errors > ar.errors.each do |attr, msg| > errors.add(attr, msg) > end > end > end > end > > The tricky part is errors.delete--the errors class doesn't expose a > delete method, even though it uses a hash as an underlying data type, > which does have a delete method. So I created a file (lib/ > error_delete.rb) with this in it to extend the Errors class and expose > it: > > module ActiveRecord > class Errors > # add function to delete a particular error message > def delete(key) > @errors.delete(key.to_s) > end > end > end > > Put in "require 'error_delete'" at the top of the file where you call > the delete function. Hope that's helpful! > > > On Jul 29, 9:49 pm, Usman Akram <[EMAIL PROTECTED]> > wrote: >> > I was wondering the same thing...Have you found a solution? >> >> No man just waiting for some help. its not a bug the validation takes >> place only once I just dont know how to switch off the invalid record >> notification. u can see the custom validation messages are being sent >> out but also along with the invalid child validation . if you find >> something kindly inform >> Regards! >> Usman >> >> -- >> Posted viahttp://www.ruby-forum.com/. > > > --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---