Old Echo
2007-Dec-31 02:03 UTC
validates_format() gets called before before_validation()??
I am pretty confused by this issue: in my model, I am using a before_validation callback and a validates_format_of method call. My before_validation method does some attribute massaging to assign nil to an attribute if it''s found to contain certain special characters. My validates_format_of method has :allow_nil => true and should only fire if none of the special characters are found. So here''s where the confusion occurs: when I try to create a new record, my validates_format_of method complains, saying that the data is invalid. However, when I dump out what''s being validated, it looks like my before_validation hasn''t fired yet - and thus it is trying to validate on those disallowed characters, which of course doesn''t work (nor should it). Okay, so far, so good. I''ve looked around on the forums and in my AWDWR book, and the consensus seems to be that when you call @some_ar_object.save, there''s an established hierarchy for how callbacks are fired: before_validation ... (validates_whatever fires here?) after_validation ... before_save before_create / before_update INSERT / UPDATE OPERATION ... That all makes sense as well. However, am I incorrect in assuming that methods like "validates_whatever" get fired in between before_validation and after_validation? That is my intuitive guess, but Rails doesn''t seem to be behaving that way. I''m sorry if there''s something really obvious I''m missing, but I''m pretty confused right now. Any help is appreciated! :) Thanks, kodama -- Posted via http://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-/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?hl=en -~----------~----~----~----~------~----~------~--~---
Old Echo
2007-Dec-31 06:01 UTC
Re: validates_format() gets called before before_validation(
Nobody has any suggestions? -- Posted via http://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-/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?hl=en -~----------~----~----~----~------~----~------~--~---