I have one form in which i enter Person data and Employee Data. A Person and Employee model are used. I am using a legacy schema, so this is forced. How do i use save the data while using rails form validation?? I only want both models to save if they both save. Controller : This odviously doesnt work: def create_employee_and_person employee = Employee.new(params[:employee]) person = Person.new(params[:person]) employee.person = person if employee.save and person.save .... ..... Any help would be greately appreciated -- Posted via http://www.ruby-forum.com/.
Chris
2006-Mar-27 10:44 UTC
[Rails] Re: Form Validation with 2 models on form. Nubee Question
I have found the answer here : http://rails.techno-weenie.net/question/2006/2/23/validating_multiple_form_fields I need to check that each model is valid : if model1.valid? and model2.valid? .... -- Posted via http://www.ruby-forum.com/.
Lucifron
2006-Mar-29 08:47 UTC
[Rails] Form Validation with 2 models on form. Nubee Question
Chris-45 wrote:> > I have one form in which i enter Person data and Employee Data. A Person > and Employee model are used. I am using a legacy schema, so this is > forced. > > How do i use save the data while using rails form validation?? I only > want both models to save if they both save. > > Controller : > > This odviously doesnt work: > > def create_employee_and_person > employee = Employee.new(params[:employee]) > person = Person.new(params[:person]) > employee.person = person > > if employee.save and person.save > .... > ..... > > Any help would be greately appreciatedI''d use a transaction spanning both updates. -- View this message in context: http://www.nabble.com/Form-Validation-with-2-models-on-form.-Nubee-Question-t1348406.html#a3646024 Sent from the RubyOnRails Users forum at Nabble.com.