Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveAdmin batch_action template error and no update

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.

like image 402
Mark Fraser Avatar asked Dec 19 '12 23:12

Mark Fraser


1 Answers

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.

like image 157
Mark Fraser Avatar answered Oct 18 '22 14:10

Mark Fraser