-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Support nested forms for has_many relationships #546
Conversation
Closes #192 Feature: When I create or edit a model that has_many nested models, I want to view and edit the attributes of the nested models so I can set up all the relationships with a single form. Implementation: Introduce a new field type, `NestedHasMany`. I considered building the feature into the existing `HasMany` field, but this would get in the way of `HasMany` relationships that aren't directly nested, such as in many-to-many relationships. The `NestedHasMany` field builds off of the [Cocoon] gem. It renders fields from the nested model, based on the fields defined in the nested model's dashboard class. Cocoon provides helpers and javascript to easily add and remove nested form fields from the page. [Cocoon]: https://github.com/nathanvda/cocoon
def self.permitted_attribute(associated_resource) | ||
{ | ||
"#{associated_resource}_attributes".to_sym => | ||
associated_attributes(associated_resource) |
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.
Put a comma after the last item of a multiline hash.
@@ -24,6 +24,7 @@ Gem::Specification.new do |s| | |||
s.add_dependency "rails", "~> 4.2" | |||
s.add_dependency "sass-rails", "~> 5.0" | |||
s.add_dependency "selectize-rails", "~> 0.6" | |||
s.add_dependency "cocoon", "~> 1.2" |
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.
🔤 this into the existing list?
In #476, we decided on a plugin structure for new field types. Nested It's rough but functional. PRs are welcome on that repository. |
Closes #192
Feature:
When I create or edit a model that has_many nested models,
I want to view and edit the attributes of the nested models
so I can set up all the relationships with a single form.
Implementation:
Introduce a new field type,
NestedHasMany
.I considered building the feature into the existing
HasMany
field,but this would get in the way of
HasMany
relationshipsthat aren't directly nested, such as in many-to-many relationships.
The
NestedHasMany
field builds off of the Cocoon gem.It renders fields from the nested model,
based on the fields defined in the nested model's dashboard class.
Cocoon provides helpers and javascript
to easily add and remove nested form fields from the page.
Preview
Next Steps