My ActiveAdmin registered model has an "active" boolean field. I want to include a batch action to "activate" multiple records at once.
I am trying to follow the instructions at:
http://activeadmin.info/docs/9-batch-actions.html
for doing a custom batch action and I am having two problems.
I have this:
ActiveAdmin.register Venue do
batch_action :deactivate do |selection|
Venue.find(selection).each do |v|
v.active = false
end
end
end
When I try to activate something I get a template not found error. It is looking for a "batch_action" template. I didn't see anything in that doc about needing to also add a template. If I add a template with that name the error goes away and it displays the template...this is of course not what I want. I want it to just redisplay the index.
In either case (with or without a template in place), the model is not being updated. I can see in the log where it just does a select for the selected records and does nothing else.
I got rid of the issues by doing the following:
batch_action :activate do |selection|
Venue.find(selection).each do |v|
v.active = true
v.save
end
redirect_to :back #this ensures any current filter stays active
end
The 'save' part seems obvious but the example in the docs threw me off on my first attempt. It seems like this would be a more relevant example for the docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With