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

Support nested forms for has_many relationships #546

Closed
wants to merge 6 commits into from
Closed

Conversation

c-lliope
Copy link
Contributor

@c-lliope c-lliope commented Apr 15, 2016

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.

Preview

nested

Next Steps

  • Needs some design love
  • Needs tests
  • It would be great to have people test this on their own apps and report bugs before we merge

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)

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"
Copy link
Contributor

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?

@c-lliope
Copy link
Contributor Author

In #476, we decided on a plugin structure for new field types. Nested has_many forms are a good candidate for a plugin, so I extracted this code out to https://github.com/graysonwright/administrate-field-nested_has_many.

It's rough but functional. PRs are welcome on that repository.

@c-lliope c-lliope closed this Apr 21, 2016
@c-lliope c-lliope deleted the nested branch April 21, 2016 05:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants