You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Continuing from a conversation in #312, building a form that is compatible with Rails accepts_nested_attributes_for and ActionController::Parameters is a bit fussy. When you use Rails form helper fields_for to act on a list from a has_many relationship it generates field names like user[things_fields][0][name].
To duplicate this behavior with Phlex::Collection I was taking advantage of the @index ivar. @joeldrapper cut that for concerns that folks would, for example, misuse it to poorly replicate things you should do with CSS.
Made an executable test gist demonstrating the inputs ActionController::Parameters demands to give us the shape accepts_nested_attributes_for demands.
So we need a unique integer key. Alternatives to Phlex::Collection passing the index could be:
Generating a timestamp
Using the record ID, tho this is tricky if you use UUID keys, which I do
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Continuing from a conversation in #312, building a form that is compatible with Rails
accepts_nested_attributes_for
andActionController::Parameters
is a bit fussy. When you use Rails form helperfields_for
to act on a list from ahas_many
relationship it generates field names likeuser[things_fields][0][name]
.To duplicate this behavior with
Phlex::Collection
I was taking advantage of the@index
ivar. @joeldrapper cut that for concerns that folks would, for example, misuse it to poorly replicate things you should do with CSS.Made an executable test gist demonstrating the inputs
ActionController::Parameters
demands to give us the shapeaccepts_nested_attributes_for
demands.So we need a unique integer key. Alternatives to
Phlex::Collection
passing the index could be:Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions