Skip to content

Commit 9cc13d3

Browse files
committed
Add docs for using has_many forms featuring :allow_destroy
1 parent e8d2776 commit 9cc13d3

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

docs/5-forms.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,32 @@ Then implement app/views/admin/posts/_form.html.erb:
3737
<%= f.inputs :title, :body %>
3838
<%= f.actions :commit %>
3939
<% end %>
40+
41+
## Nested Resources
42+
43+
You can create forms with nested models using the `has_many` method:
44+
45+
ActiveAdmin.register Post do
46+
47+
form do |f|
48+
f.inputs "Details" do
49+
f.input :title
50+
f.input :published_at, :label => "Publish Post At"
51+
end
52+
f.inputs "Content" do
53+
f.input :body
54+
end
55+
f.inputs do
56+
f.has_many :categories, :allow_destroy => true do |cf|
57+
cf.input :title
58+
end
59+
end
60+
f.actions
61+
end
62+
63+
end
64+
65+
The `:allow_destroy` option will add a checkbox to the end of the nested form allowing
66+
removal of the child object upon submission. Be sure to set `:allow_destroy => true`
67+
on the association to use this option.
68+

0 commit comments

Comments
 (0)