This problem has been killing me. I played around with Ryan Bates complex forms, but I can't quite figure out my problem. I have this schema:
Location has_many :targets
Target has_many :target_classifications
All locations are shown on the page. A user may create a target for any location dynamically through jscript, which then adds a table row under the location 3 selects (that contain available classifications to the target) and a target value. Any number of targets can be created for any location before clicking save.
I'm using rjs to render a target_partial, which has this code:
I'm using fields_for in this way:
for each select. When sumbmitted, I get this hash:
"new_targets"=> {"7"=>[{"id"=>"13"}, {"id"=>"15"}, {"value"=>"67", "id"=>""}], "4"=> [{"id"=>"12"}, {"id"=>"15"}, {"value"=>"23", "id"=>""}, {"id"=>"11"}, {"id"=>"16"}, {"value"=>"67", "id"=>""}]},
So, it separates each target by location ("7" and "4" in this case), but doesn't separate each target. What I want is this:
"new_targets"=> {"7"=>[ {"target"=>[{"id"=>"13"}, {"id"=>"15"}, {"tonnes"=>"67"}]} ], "4"=>[ {"target"=>[{"id"=>"12"},{"id"=>"15"},{"tonnes"=>"23"]}, {"target"=>[{"id"=>"11"},{"id"=>"16"},{"tonnes"=>"67"]} ] }
so I can iterate through each target for each location. I can't seem to add in a new [target] brace in my field_for method (it blows up), but that's kind of what I want to do. Any thoughts?