avo
avo copied to clipboard
Bulk update back-end
Context
We'd like to enable users to bulk-update records from the Index page.
We need a back-end for it.
Approach
Create a BulkUpdateController which will take in a payload and update those records accordingly.
- execute field validation from the model (Rails should do it for us)
- accepted params should be verified
- fields marked as
disabledshould not be updated
- fields marked as
- ensure the values are updated through
fill_fieldmethod for every field
Possible payload this controller action can take:
{
payload: [
{
param: "user_12o3211o3i3h" # or just the id
resource_type: Avo::Resources::User,
body: {
first_name: "John",
age: 33
}
},
{
param: "user_k3k6no2i" # or just the id
resource_type: Avo::Resources::User,
body: {
first_name: "John",
age: 33
}
},
{
param: 123
resource_type: Avo::Resources::Post,
body: {
title: "What a great day",
body: "# Lorem ipsum"
user_id: "user_12o3211o3i3h"
}
}
]
}
Approach video: https://www.loom.com/share/f41a28048b8d4b80a3296e80d85fab41?sid=f1ba9ce6-41e2-48c0-9d3b-b4734169317f
Comment for assignment, I will give it a try.
Some inspiration:
- https://x.com/bradgessler/status/1887187002459877425
- https://superails.com/posts/ruby-on-rails-86-bulk-actions-edit-multiple-selected-records