-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Array of nested fields_for bug #26931
Comments
I dug around the source, and the culprit is clearly here. Is there proper way to make an array of objects without having to name each field manually? |
I am able to reproduce this as well. |
Can you take your code from above and create an executable test script using one of the templates here, that would demonstrate the problem you are seeing? I'm trying to reproduce the issue locally, and am having some trouble doing so. |
I was able to reproduce this too, but it does not seem to be a bug, as you pointed, the problem is that the object name is overwrote when an auto index is defined. So if you have an array of users, you can do something like this: <%= fields_for 'users', @user {index: @user.id} do |user_fields| %> So the user ID is used as the index, and the object name will not be overwrote. |
@erickueen this would be fine otherwise, but I'm also adding new users to the form dynamically via javascript. This would mean that I couldn't just copy a template to the form, but have to change all the field names as well. |
Since it affects the entire form, should not mutate `object_name` of class. Fixes rails#26931
I am trying to construct a form which should be structured like this (simplified for clarity):
That is,
users
is an array of objects with nested attributes.Steps to reproduce
In a view:
@user.contacts
is a hash, which contains contact information for the user.As you can see, after the
fields_for :contacts
, the name of theuser_fields
builder is stripped of one set of[]
. This interferes with the rest of the form.Expected behavior
The above should approximately render as:
Actual behavior
System configuration
Rails version: 5.0.0.1
Ruby version: 2.3.0
The text was updated successfully, but these errors were encountered: