You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/4.0/actions.md
+42-1Lines changed: 42 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -127,7 +127,7 @@ You may use the [custom controls](./custom-controls.html) feature to show action
127
127
128
128
## Collect input with fields
129
129
130
-
An action can define fields, shown to the user in the action's modal. They work the same way as fields on resources. When the action runs on a single record the fields are hydrated from that record; otherwise they're plain form inputs. The submitted values arrive in `handle` as the `fields` argument.
130
+
An action can define fields, shown to the user in the action's modal. Most work the same way as fields on resources. When the action runs on a single record the fields are hydrated from that record; otherwise fields that do not depend on a record render as plain form inputs. Association fields are an exception, as described below. The submitted values arrive in `handle` as the `fields` argument.
131
131
132
132
```ruby
133
133
# app/avo/actions/toggle_inactive.rb
@@ -141,6 +141,47 @@ end
141
141
142
142
Check out the [Fields page](./fields.md) for everything fields can do.
143
143
144
+
### Choose an associated record in a collection action
145
+
146
+
A [`belongs_to` field](./associations/belongs_to.html) needs one current record to resolve its association. It works when you run the action from a record's <Show /> view or select exactly one record on the <Index /> view because Avo hydrates the action with that record. It cannot render when you select multiple records or run a standalone action because there is no single current record.
147
+
148
+
For a short list of choices, use a [`select` field](./fields/select.html) with options loaded when the form renders:
The endpoint receives the search text in `params[:q]` and returns objects with `value` and `label` keys. Both alternatives submit the selected ID as `fields[:user_id]`.
184
+
144
185
## Write the `handle` method
145
186
146
187
`handle` is where your business logic lives. It receives keyword arguments:
0 commit comments