Skip to content

Commit

Permalink
Merge pull request #109 from avo-hq/alias_query_as_records_on_actions
Browse files Browse the repository at this point in the history
alias query as records on actions
  • Loading branch information
Paul-Bob authored Sep 11, 2023
2 parents 0311ad6 + f071af1 commit a84a5ef
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions docs/3.0/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class Avo::Actions::ToggleActive < Avo::BaseAction
end

def handle(**args)
records, fields, current_user, resource = args.values_at(:records, :fields, :current_user, :resource)
query, fields, current_user, resource = args.values_at(:query, :fields, :current_user, :resource)

records.each do |record|
query.each do |record|
if record.active
record.update active: false
else
Expand Down Expand Up @@ -67,13 +67,13 @@ More about this on the [authorization page](./authorization#attachments).

![Actions](/assets/img/actions/action-fields.jpg)

The `handle` method is where the magic happens. That is where you put your action logic. In this method, you will have access to the selected `records` (if there's only one, it will be automatically wrapped in an array) and the values passed to the `fields`.
The `handle` method is where the magic happens. That is where you put your action logic. In this method, you will have access to the `query` (same value as `records` (if there's only one, it will be automatically wrapped in an array)) and the values passed to the `fields`.

```ruby
def handle(**args)
records, fields = args.values_at(:records, :fields)
query, fields = args.values_at(:query, :fields)

records.each do |record|
query.each do |record|
if record.active
record.update active: false
else
Expand Down

0 comments on commit a84a5ef

Please sign in to comment.