Note that there are some explanatory texts on larger screens.

plurals
  1. PORails Dynamic Multi Model Form attributes
    text
    copied!<p>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:</p> <pre><code> Location has_many :targets Target has_many :target_classifications</code></pre> <p>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.<br> I'm using rjs to render a target_partial, which has this code: I'm using fields_for in this way:</p> <pre><code> </code></pre> <p>for each select. When sumbmitted, I get this hash:</p> <pre>"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"=>""}]}, </pre> <p>So, it separates each target by location ("7" and "4" in this case), but doesn't separate each target. What I want is this:</p> <pre> "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"]} ] } </pre> <p>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?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload