Constantin Gavrilescu
2008-Feb-03 11:26 UTC
ActiveRecord object.valid? triggers unexepected results
I''m editing an ActiveRecord object in a session through AJAX, updating it with object.attributes = params[:object], and validating it with object.valid? Because it''s associated with other objects in a form, I want to save them all together. The surprise was that object.valid? triggers after_validation_on_update. I''m having an audit log and I was getting bogus entries. http://api.rubyonrails.org/classes/ActiveRecord/Validations.html#M001316 valid?() Runs validate and validate_on_create or validate_on_update and returns true if no errors were added otherwise false. valid?() should run all validations, but not trigger after_validation callbacks. This is not just a rant... I''m looking for solutions? How can I have an audit log on updates and running valid()? without polluting my audit log? -- 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 -~----------~----~----~----~------~----~------~--~---
Constantin Gavrilescu
2008-Feb-03 11:49 UTC
Re: ActiveRecord object.valid? triggers unexepected results
Constantin Gavrilescu wrote:> How can I have an > audit log on updates and running valid()? without polluting my audit > log?Well.. I gave my own answer. Replace after_validation_on_update with before_update. I think the misunderstanding came from the fact that I interpreted "after_validation on_update" when it actually was "after validation_on_update". -- 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 -~----------~----~----~----~------~----~------~--~---