Hi Marnen, Thanks for taking an interest. I really appreciate you and Rick taking the time to check on my problem.
I finally made the whole thing work (kind of). I know I am doing something wrong because the associated objects validations are not being hit, probably because I am creating the wrong type of object, ('project' rather than 'person_project') for the form as you can see in the params hash below, but at this point I am already too tired of the problem and I am also too late to keep looking into it or I won't meet the deadline I have. I would like to fix it in the (near) future, though, so here goes some more info in case it helps. This is a sample of the params hash (edited): person: !map:HashWithIndifferentAccess # person fields and values go here person_projects_attributes: !map:HashWithIndifferentAccess "0": !map:HashWithIndifferentAccess project_attributes: !map:HashWithIndifferentAccess id: "000267" project_id: "000267" supervisor_id: "10" id: "10326" "1": !map:HashWithIndifferentAccess project_attributes: !map:HashWithIndifferentAccess id: 000392 project_id: 000392 supervisor_id: "2" I ended up validating the associated objects values by hand in the controller. Something like this: def validate_person_projects_list params[:person][:person_projects_attributes].each_pair do |index, person_project| if person_project[:supervisor_id].blank? @person.errors.add_to_base 'All projects must have a supervisor.' return end end end # def validate_person_projects This is the form (edited): <% form_for :person, @person, :url => { :action => "approval" } do |f| %> # person's fields go here <% for @person_project in @person.person_projects %> <% f.fields_for :person_projects, @person_project do | pp_fields| %> <%= pp_fields.hidden_field :project_id -%> <%= pp_fields.select :supervisor_id, @person_project.supervisors.map {|s| [s.id.to_s + ' -> ' + s.lname.strip + ', ' + s.fname.strip, s.id]}.sort {|a, b| a[0] <=> b[0]} -%> <% end %> <% end %> <%= submit_tag 'Save' -%> <% end -%> @person_project#supervisors is a model method that will return the list of supervisor objects to choose from: current record's, current record project's and current record project contractors'. Thanks again for taking the time. I really appreciate it. On Jan 10, 11:19 am, Marnen Laibow-Koser <li...@ruby-forum.com> wrote: > pepe wrote: > > [...] > > > Unfortunately I am not as comfortable with Rails yet as I would like > > to be and I have been working on this on and off for more than 2 weeks > > now. I have hit every possible page (many times) I could find with > > information about complex forms and multi record processing, watched > > the railscasts, hit the books, everything… Depending on the approach I > > take sometimes validations are skipped or new person_project records > > are not saved, or… I’ve hit every possible roadblock. > > Which tests are failing under which circumstances? > > > > > If you guys know how to solve this riddle I would be very, very > > thankful. > > > Thanks a lot. > > Best, > -- > Marnen Laibow-Koserhttp://www.marnen.org > mar...@marnen.org > -- > Posted viahttp://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-t...@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.