ActiveScaffoldBatch
This plugin enables batch actions, allowing users to perform operations on multiple records simultaneously. Perfect for administrative tasks requiring bulk updates or deletions.
Description
ActiveScaffoldBatch enables batch actions, allowing users to perform operations on multiple records simultaneously. This is useful for administrative tasks that require bulk updates or deletions, optimizing time and effort for developers.
Installation
Add the following line to your Gemfile:
gem 'active_scaffold_batch'Then run:
bundle installUsage & Options
It provides 3 actions: batch_create, batch_update and batch_delete.
After installation, you can enable batch processing in your ActiveScaffold configuration adding any of those actions to default actions:
ActiveScaffold.set_defaults do |config|
config.actions << :batch_update
endOr adding them in your controller:
class UsersController < ApplicationController
active_scaffold :user do |config|
config.actions << :batch_create
end
endExample Code
If you want to allow bulk activation of users, you can define a custom action:
class UsersController < ApplicationController
include ActiveScaffold::Actions::BatchBase
active_scaffold :user do |config|
config.action_links.collection.add :batch_activate, label: 'Activate Users',
confirm: 'Are you sure you want to activate the selected users?',
parameters: {batch_scope: 'marked'}
end
def batch_activate
batch_action
end
protected
def batch_activate_marked
activated = 0
each_marked_record do |record|
if record.update(active: true)
record.as_marked = false
activated += 1
else
error_records << record
end
end
end
end