당신은 단지이, 당신은 문제를 얻는 경우?
# ability.db
def initialize(user)
case
# ...
when user.super_admin?
can :manage, :all
when user.admin?
can :manage, Profile, :institution_id => user.institution.id
#
# ...
end
이 허용됩니다 Profile.accessible_by(current_user)
을, 당신은 최고 관리자가 모든 게시물에 액세스하려면 current_user.profiles
class AdminUser
has_one :institution
has_many :profiles, :through => :institution
end
ActiveAdmin.register Profile do
scope_to :current_user #here comes the variable which set in initializer
end
, 당신이 사용할 수있는 동일하게 여기있는 : 옵션
ActiveAdmin.register Profile do
scope_to :current_user, :association_method => :admin_profiles
end
# in class User
def admin_profiles
if super_admin?
Profile.unscoped
else
profiles
end
end
에게 association_method를 까다로운 해결책은이를 일반화하고 위임자 클래스를 프록시로 사용하여 모든 모델에서 슈퍼 관리자를 선택 해제 할 수 있습니다. 내가 요청할 수 있습니다.
그래서 기관을 통해 관리자와 프로필간에 가상의 관계를 만들어야합니다. 고마워요 !! 당신의 대답은 active admin & cancan에 대한 많은 것들을 지 웁니다 – chaitanya
만약 사용자가 super_admin이라면 어떻게 할 수 있습니까? 예를 들면. 그는 모든 프로필을보아야합니까? – chaitanya
내 업데이 트를 참조하십시오 hth –