Skip to content
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

Current design is crippling nested "has_many" forms #1033

Closed
baldursson opened this issue Nov 27, 2017 · 2 comments
Closed

Current design is crippling nested "has_many" forms #1033

baldursson opened this issue Nov 27, 2017 · 2 comments
Labels
bug breakages in functionality that is implemented views-and-styles how administrate looks and is interacted with

Comments

@baldursson
Copy link

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 is nil, 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 than Rails Admin and Active 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.

@nickcharlton
Copy link
Member

Hi @baldursson!

Thank you for opening this comprehensive issue. I feel like I need to try this out a little so that I can understand it better. Would you be able to provide a small sample app which shows this not working very well and/or with your potential workaround?

I suspect we might be in a situation where we need a little bit of refactoring, but that's fine. It's going to happen as slightly more complex use cases are seen.

Additionally, I'll see what I can do about your PRs on @Graysonwright's administrate-field-nested_has_many, too.

@nickcharlton nickcharlton added bug breakages in functionality that is implemented views-and-styles how administrate looks and is interacted with labels Jan 2, 2020
@nickcharlton
Copy link
Member

I'm going to close this as it's been quite a while since the last activity and there's nothing specifically actionable from this.

We are doing some work with improving the underlying fields and so I'd expect that to help out a bunch here (#1506, etc), but please open new issues if there's something specific we can address.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug breakages in functionality that is implemented views-and-styles how administrate looks and is interacted with
Projects
None yet
Development

No branches or pull requests

2 participants