Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed index and auto index for nested fields_for [#327 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
- Loading branch information
Showing
2 changed files
with
136 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1b4b1aa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am attempting to utilize mass-assign for my models, but can’t get the update_attributes to work correctly when I have association_collections as child models.
My create methods work fine, since the hash passes in an Array value for these collections. I.E.:
emails => [ {…}, {…} ] )
But, when I try to edit/update my model, the field names in the form naturally have the :id of the email included in them, so that the resulting value passed to the mass-assign is not an Array, but a Hash of this form:
emails => {“5” => {…}, “6” => {…}}
Where the 5 and 6 are the :id values of the respective emails. This gets passed into the update_attributes, which eventually gets to:
AssociationCollection.replace(other_array)
which assumes “emails” to be an Array. Shouldn’t this replace method be “smarter” so that if a Hash is passed in, it will ascertain the :id values from it, and then reassign the model attributes accordingly?
Furthermore, what would happen if there were a combination of updated models (emails) and perhaps one new email (that didn’t have an :id). Does the mass-assign functionality handle this situation?
Any help would be appreciated.
-Glenn
1b4b1aa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generation of HTML element id and form field name are inconsistent after 2nd level of nesting.
Generates this:
You notice that the in the 3rd level that the 2nd level ID is missing and that the “[]” are enclosed within the first field.
I was able to get the the above form to work as expected by removing the brackets and explicitly setting the id.Generation of HTML element id and form field name are inconsistent after 2nd level of nesting.
I perused the code, but am not familiar enough with things to spot anything.
Thanks for the original patch. Made my code less ugly.
1b4b1aa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Textile Reference I followed said to do pre and code.
Let’s try just code so you can see the html. I also took out lt and gt.
form action="/inventory/requests/350903690" class="edit_request" id="edit_request_350903690" method="post"> input id="request_existing_line_item_attributes_51161156_equipment_type_id" name="request[existing_line_item_attributes][51161156][equipment_type_id]" size="30" type="text" value="691081111" /
```
input id=“request_existing_line_item_attributes___existing_equipment_line_item_attributes_860256615_equipment_id” name=“request[existing_line_item_attributes[]][existing_equipment_line_item_attributes]860256615[equipment_id]” size=“30” type=“text” value=“1029003634” /
```
/form