On Feb 18, 2012, at 12:06 PM, Peter Pavlovich wrote: > Greetings, > > I have a question for the experts in the group! Here is the scenario: > • Two business object classes: Person and Address > • A relationship between these two classes: Person has an address. > • A view in which I would like to create a person with an address on > the same screen. > • Using a custom hobo tag as a reusable address editor and embedding > that tag on the person editor screen. > • The Address class has a few validations on its attributes (city and > state must be filled in) > • The Person class has a few validations on its attributes (first and > last name must be filled in) > Here is the problem: When I click save person, and I have filled in all the > correct information for both the person and the address fields, all saves > correctly. If I leave out a required field on the person, all works as > expected with the error message and highlighted field. If I leave out a > required field on the address, but fill out the person fields correctly, the > person saves correctly but the address does not save at all (person saves > with no address attached and no address object is saved). I would have > expected that the whole save would have failed with an appropriate error > message displayed and that the "bad" address object fields would have been > highlighted. > > What is the correct "hobo" and/or "rails" way of dealing with validation of > subordinate or child objects during save and/or update operations? Do I need > to do some sort of transaction management or override the "valid?" method on > the Person class?
Best place to start is the Rails validation 'validates_associated :address'. Not sure what that will do regarding error messages, though - you may just get a generic "Address must be valid" message instead of the detailed errors. --Matt Jones -- You received this message because you are subscribed to the Google Groups "Hobo Users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/hobousers?hl=en.
