Actions
This is the official documentation of the agent_ruby
Ruby agent.
Sooner or later, you will need to perform actions on your data that are specific to your business.
Moderating comments, generating invoices, logging into a customer’s account, or banning users are exactly the kind of important tasks to unlock to manage your day-to-day operations.

In your code
To create an Action, you will first need to declare it in your code for a specific collection. Here we declare a "Mark as Live" Action for the companies
collection.
The action behavior is implemented in the execute
function.
include ForestAdminDatasourceCustomizer::Decorators::Action::Types
include ForestAdminDatasourceCustomizer::Decorators::Action
@create_agent.customize_collection('companies') do |collection|
collection.add_action(
'Mark as Live',
BaseAction.new(
scope: ActionScope::GLOBAL,
description: "Mark the company as live",
submit_button_label: "Validate 🫵",
form: [
{
type: FieldType::LAYOUT,
component: 'Page',
next_button_label: "Go to address",
elements:[
{type: FieldType::DATE, label: "Live date",id: "LiveDate"},
{type: FieldType::STRING, label: "Exist since", id: "CreationDate"},
{type: FieldType::LAYOUT, component: "Separator"},
{
type: FieldType::LAYOUT,
component: "Row",
fields: [
{type: FieldType::BOOLEAN, label: "CreditCard ?" id: "WithCreditCard"},
{
type: FieldType::STRING,
if_condition: ->(ctx) {ctx.form_values?.WithCreditCard == true},
label: "Number",
id: "CreditCardNumber",
},
],
},
],
},
{
type: FieldType::LAYOUT,
component: "Page",
previous_button_label: "Go back to identity",
elements: [
{
type: FieldType::LAYOUT,
component: "Row",
fields: [
{type: FieldType::NUMBER, label: "StreetNumber"},
{type: FieldType::NUMBER, label: "StreetName"},
],
},
{type: FieldType::LAYOUT, component: "Separator"},
{type: FieldType::NUMBER, label: "PostalCode"},
{type: FieldType::NUMBER, label: "City"},
{type: FieldType::LAYOUT, component: "Separator"},
{type: FieldType::NUMBER, label: "Country"},
],
},
]
) do |context|
# Implement your controller here.
end
)
end
execute
require
The callable called when the action is executed, with context
and result builder
as parameters. See context and result builder pages for more details.
form
optional
A list of static fields to be input by the user or a function called with context
as parameters which returns a list of fields. See form page for more details.
description
optional
An optional description of the action. Default: null
submit_button_label
optional
A custom label for the submit button. Default: the action name
In the admin panel
After declaring it, the Action will appear in the Smart Actions tab within your Collection Settings.
You must make the Action visible there if you wish users to be able to see it in this Team.

Last updated
Was this helpful?