0
votes

I'm developing an app in rails and I'm using ActiveAdmin for admin backend.

I would list admin users in AdminUser page regard to certain conditions:

  • List only current_admin_user

Now, I have this code, that lists all the admin users registered:

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

How can I list only active admin users?

Thanks in advance.

2

2 Answers

1
votes

you just need to override scoped collection method.

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

That's it. Hope it will help you

0
votes

I would suggest this solution:

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

#scoped_collection should return an ActiveRecord::Relation, so you need to "make" it from your current_admin_user