Active Admin:在 AdminUser 页面中仅列出某些管理员用户

Active Admin: List only certain admin users in AdminUser page

我正在 rails 开发应用程序,我正在使用 ActiveAdmin 作为管理后端。

我会根据特定条件在 AdminUser 页面中列出管理员用户:

现在,我有这段代码,它列出了所有注册的管理员用户:

ActiveAdmin.register AdminUser do

  menu :label => "Profilo", :priority => 4

  permit_params :email, :password, :password_confirmation

  #List of admin_users connected to the curent_user
  index  do
    selectable_column
    id_column
    column :email
    column :current_sign_in_at
    column :sign_in_count
    column :created_at
    actions
  end

end

如何只列出活跃的管理员用户?

提前致谢。

您只需要重写作用域收集方法。

ActiveAdmin.register AdminUser do

  menu :label => "Profilo", :priority => 4

  permit_params :email, :password, :password_confirmation

  #List of admin_users connected to the curent_user
  index  do
    selectable_column
    id_column
    column :email
    column :current_sign_in_at
    column :sign_in_count
    column :created_at
    actions
  end
  controller do
    def scoped_collection
          #your logic
          current_admin_user
    end
  end

end

就是这样。希望对你有所帮助

我会建议这个解决方案:

ActiveAdmin.register AdminUser do
  # ... your code
  controller do
    def scoped_collection
      AdminUser.where(id: current_admin_user.id)
    end
  end
end

#scoped_collection 应该 return 一个 ActiveRecord::Relation,所以你需要 "make" 从你的 current_admin_user