我正在使用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
如何仅列出有效的管理员用户?
提前致谢。
答案 0 :(得分:1)
你只需要覆盖作用域集合方法。
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
那就是它。希望它能帮到你
答案 1 :(得分:0)
我会建议这个解决方案:
ActiveAdmin.register AdminUser do
# ... your code
controller do
def scoped_collection
AdminUser.where(id: current_admin_user.id)
end
end
end
#scoped_collection
应返回ActiveRecord :: Relation,因此您需要从current_admin_user