Last time I ve talked about batch updates. Today I would like to focus on batch destroy.
I will assume that you have read my last post.

Enabling batch_destroy action

class PlayersController < ApplicationController
  active_scaffold :player do |conf|
    ....
    conf.actions << :batch_base 
    conf.actions << :batch_destroy 
    ....
  end
end

If you reload your page, you will see another entry in batch collection pop-up menu, which you might use to destroy marked or listed records.

Process Mode Configuration

There s one thing I have nt mentioned so far. In default mode batch_destroy will perform a “normal” activerecord destroy, which includes validation, record base_authorization and callbacks,…. That might take quite some time if you want to destroy a huge number of records.

You can configure to speed up, but you have to pay a price:

class PlayersController < ApplicationController
  active_scaffold :player do |conf|
    ....
    conf.batch_destroy.process_mode = :delete_all 
    ....
  end
end

process_mode delete_all means that we will use ActiveRecords delete_all method to destroy all records.
But be careful and let me tell you about the price you have to pay:

  • No record base authorization
  • No record level errors
  • No ActiveRecord callbacks, validations,…

Just to complete this story, you ve got same configuration option in batch_update.

Wish you a great weekend!

About these ads