Current design is crippling nested "has_many" forms #1033
Labels
bug
breakages in functionality that is implemented
views-and-styles
how administrate looks and is interacted with
I found a design flaw that affects nested has many forms. I found it when using the "
administrate-field-nested_has_many
" gem (https://github.com/graysonwright/administrate-field-nested_has_many), but the flaw will affect any implementation of nested has_many forms. Well, it affects fields that rely on modifications on the data, since the field models are never aware of which instance they are working on.Here's the story:
I had a nested form with a custom field, and a text field. The text field would work just fine, but my custom field didn't. I quickly realized that the
data
attribute on the custom field was nil. Why?Well when a form is created, a list of field models is created based on the dashboard. That's a one to one relationship. So at that point the whole relation will be sent as resource to the field within a has_many relation (an instance of
ActiveRecord::Associations::CollectionProxy
to be exact). That's why data isnil
, because normally the data attribute is extracted from the resource by sending it the attribute name. Can't be done here.As far as I have been able to see, it is only at render time when we know exactly which item in the collection the model is supposed to work with. So my dirty fix was to let the view send the index to the field model, so it could create the data attribute from its collection resource. Not a sustainable solution exactly.
Does anyone have a better idea of how to fix this easily, or is the current model in need of extensive refactoring?
I believe nested has_many forms is a must have in most real world admin interfaces, especially when
Administrate
is advertised as providing a better user experience for site admins thanRails Admin
andActive Admin
. Have to say the poor support of it in the current state is a bit alarming.Hopefully someone here has some good ideas about this issue.
The text was updated successfully, but these errors were encountered: