【问题标题】:How to remove activeadmin's batch action routes如何删除 activeadmin 的批处理操作路由
【发布时间】:2014-02-12 13:34:14
【问题描述】:

使用 Rails 3.2.12,active_admin 0.6.2/0.6.3,我在我的 ActiveAdmin 初始化程序中禁用了批处理操作:

config.batch_actions = false

但是,rake routes 显示了我所有注册的 ActiveAdmin 控制器的批处理操作路由:

$ rake routes | grep batch
            batch_action_admin_admin_users POST     /admin/admin_users/batch_action(.:format)                                               admin/admin_users#batch_action
                batch_action_admin_members POST     /admin/members/batch_action(.:format)                                                   admin/members#batch_action
           batch_action_admin_sales_agents POST     /admin/sales_agents/batch_action(.:format)                                              admin/sales_agents#batch_action
               batch_action_admin_comments POST     /admin/comments/batch_action(.:format)                                                  admin/comments#batch_action

如何删除这些路由?

我尝试用猴子补丁 this code

post :batch_action if config.batch_actions

但它不起作用。

已编辑:下面的答案都很好。有一个PR fixing this

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3.2 routes activeadmin


    【解决方案1】:

    我分析了 ActiveAdmin 的来源。这是我found:

    def resource_routes(config)
      # Some code here...
      case config
      when ::ActiveAdmin::Resource
        resources config.resource_name.route_key, :only => config.defined_actions do
          member do
            config.member_actions.each &build_action
          end
    
          collection do
            config.collection_actions.each &build_action
            post :batch_action
          end
        end
      # Code continues..
    end
    

    ActiveAdmin 根本没有配置选项。它总是生成批处理路由。

    【讨论】:

      【解决方案2】:

      查看源代码here 后,我意识到适当的猴子补丁将使用config.batch_actions_enabled?

      【讨论】:

      • 只想指出,Isaac 提交了一个修复此问题的补丁,它已被合并到 master 中。谢谢,伊萨克!
      猜你喜欢
      • 2013-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      相关资源
      最近更新 更多