活动管理员:根据活动范围修改索引表



假设我有一个ActiveAdmin模型,有两个作用域,如下所示:

ActiveAdmin.register Book do
  scope :all, default: true
  scope :smith #all books by author 'smith'
  index do
    column :title
    column :published_year
    column :author
  end
end

当用户选择"史密斯"范围时,我不想要/不需要"作者"列。

那么有没有办法访问当前范围并仅在其中一个范围中显示作者列? 我想对于此示例,我可以使用自定义视图并检查数据的实际内容,但我希望有一种更简单更好的方法。

你可以尝试这样的东西

index do
    column :title
    column :published_year
    column :author unless params['scope'] == 'smith'
  end
您还可以

访问@current_scope对象,并且可以执行@current_scope.scope_method来获取底层的作用域方法

最新更新