Rails 带参数的活动管理范围

Rails Active Admin Scope with Params

在此处解释了将活动管理员与 ActiveRecord 范围结合使用:Rails3 Active Admin: How to display only Open status records when first click on Shipments tag?

现在我正在尝试使用参数 对范围执行此操作。

在我的模型中我有:

#app/models/shipments.rb
scope :by_status, -> (status) { where(status: status) }

我希望能够在 app/admin/shipments.rb 中使用它,就像

# app/admin/shipments.rb
scope :by_status 'open'

是否有有效的管理方式来做到这一点?

您可以使用块:

  scope :open do |shipments|
    shipments.by_status('open')
  end

如果您希望这是默认范围:

  scope :open, default: true do |shipments|
    shipments.by_status('open')
  end