【问题标题】:How to use conditional statement in batch actions of Active Admin?如何在 Active Admin 的批处理操作中使用条件语句?
【发布时间】:2021-02-18 03:09:52
【问题描述】:

我在我的项目中使用活动管理员并且我正在修改批处理操作。我想对其应用 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 条件吗?

任何形式的帮助都将不胜感激。

【问题讨论】:

    标签: ruby-on-rails ruby if-statement conditional-statements activeadmin


    【解决方案1】:

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

    if(count(ids) is 1) then 你想删除它吗?

    其他

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

    【讨论】:

      猜你喜欢
      • 2012-03-03
      • 2017-02-12
      • 1970-01-01
      • 2015-06-29
      • 2017-01-25
      • 1970-01-01
      • 1970-01-01
      • 2018-01-01
      • 1970-01-01
      相关资源
      最近更新 更多