如何在 Active Admin 的批处理操作中使用条件语句?

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

我在我的项目中使用了活动管理员并且正在修改批处理操作。我想对其应用 if-else 条件。如果交易状态已完成,则显示 Are you sure you want to delete these transactions? else Do you want to delete it? 我想实现这样的目标。

这是我正在使用的演示代码 -

  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

有什么方法可以应用 if-else 条件吗?

如有任何帮助,我们将不胜感激。

您可以根据我们在“ids”变量中获取的记录数放置 if else。会像

if(count(ids) 为 1) 那么要删除吗?

其他

您确定要删除这些交易吗?