jeudi 5 novembre 2020

How to use conditional statement in batch actions of Active Admin?

I'm using active admin in my project and I'm modifying the batch actions. I want to apply if-else condtion on it. If the status of transaction is completed then show Are you sure you want to delete these transactions? else Do you want to delete it? I want to achieve something like this.

This is the demo code that I'm using -

  batch_action :destroy, :confirm => "Are you sure you want to delete these transactions?", if: proc { transaction?(:status, completed) } do |ids|
    Application::Transaction.where(id: ids).destroy_all

   redirect_to transactions_path, :notice => "Successfully destroyed transactions"
  end

Is there any way possible to apply if-else condition on it?

Any kind of help would be greatly appreciated.

Aucun commentaire:

Enregistrer un commentaire