Hmmm.. Are Cat and Dog associated to the Person model? > there may not always be a @cat or @dog
Meaning the parameters for these models will be passed in from the form but they will be empty? In which case you can have a before_validation callback and check if all the params for these models are blank. If they are, then return false. This will still throw a "Cat/Dog is invalid" validation error. That can be handled by hacking into error_messages_for. Its all quite ugly but it works. I can tell you more if you can explain the context better. On Apr 7, 2:26 pm, sshefer <shai.she...@gmail.com> wrote: > Jim Neath's walkthru (http://jimneath.org/2008/09/06/multi-model-forms- > validations-in-ruby-on-rails/) talks about validating multiple objects > before saving. His example is below: > > if @person.valid? & @cat.valid? & @dog.valid? > Person.transaction do > @person.save! > @cat.save! > @dog.save! > end > else > FAIL > end > > I am trying to do something similar but in my situation there may not > always be a @cat or @dog (there will always be a @person though). > Does anyone know of a way that I can run the same validation but allow > for the conditional presence of the 2 objects? > > Thanks. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---