docs/5-forms.md in activeadmin-1.3.1 vs docs/5-forms.md in activeadmin-1.4.0
- old
+ new
@@ -82,10 +82,16 @@
You can create forms with nested models using the `has_many` method, even if
your model uses `has_one`:
```ruby
ActiveAdmin.register Post do
+ permit_params :title,
+ :published_at,
+ :body,
+ categories_attributes: [:id, :title, :_destroy],
+ taggings_attributes: [:id, :tag],
+ comment_attributes: [:id, :body, :_destroy]
form do |f|
f.inputs 'Details' do
f.input :title
f.input :published_at, label: 'Publish Post At'
@@ -104,20 +110,23 @@
end
end
f.inputs do
f.has_many :comment,
new_record: 'Leave Comment',
- allow_destroy: -> { |c| c.author?(current_admin_user) } do |b|
+ allow_destroy: -> (c) { c.author?(current_admin_user) } do |b|
b.input :body
end
end
f.actions
end
end
```
+*NOTE*: In addition to using `has_many` as illustrated above, you'll need to add
+`accepts_nested_attributes` to your parent model and [configure strong parameters](https://activeadmin.info/2-resource-customization.html)
+
The `:allow_destroy` option adds a checkbox to the end of the nested form allowing
removal of the child object upon submission. Be sure to set `allow_destroy: true`
on the association to use this option. It is possible to associate
`:allow_destroy` with a string or a symbol, corresponding to the name of a child
object's method that will get called, or with a Proc object. The Proc object
@@ -157,10 +166,13 @@
max_date: "+1W +5D"
}
end
```
+Datepicker also accepts the `:label` option as a string or proc to display.
+If it's a proc, it will be called each time the datepicker is rendered.
+
## Displaying Errors
To display a list of all validation errors:
```ruby
@@ -185,18 +197,20 @@
f.input :password
f.input :password_confirmation
end
end
- tab 'Advanced' do
+ tab 'Advanced', html_options: { class: 'specific_css_class' } do
f.inputs 'Advanced Details' do
f.input :role
end
end
end
f.actions
end
```
+
+`html_options` allows you set additional html params for tab's menu item.
# Customize the Create Another checkbox
In order to simplify creating multiple resources you may enable ActiveAdmin to
show nice "Create Another" checkbox alongside of Create Model button. It may be