선언적 승인 및 has_and_belongs_to_many.
-
14-11-2019 - |
문제
선언적 인 승인에 문제가 있습니다.나는 has_and_belongs_to_many 협회를 가진 사용자와 역할 모델을 가지고 있습니다.
라는 역할을 만들었습니다. My Authorization_rules.rb의 중재자
역할 중재자를 가진 사용자는 중재자 역할이 할당 된 사용자 만 사용자를 가져옵니다 ??-> user.with_permissions_to (: 인덱스)
나는 그것이 그렇게 될 수 있다고 생각했다 :
role :moderator do
has_permission_on :users, :to => :index do
if_attribute :roles => contains { ????? }
end
end
.
또한 도움이 될 것이라고 생각 했으므로 사용자 모델에서 named_scope를 만들었습니다 ...
class User
has_and_belongs_to_many :roles
named_scope :by_role, lambda { |role|
{
:include => :roles,
:conditions => {"roles.name" => role}
}
}
end
.
누구든지 선언적으로이를 수행 할 수 있는지 알고 있습니까?
도움말셔서!
해결책
I did something similar in one of my projects but found dec_auth really confusing at the time. I think this is what you need to do:
authorization_rules.rb:
role :moderator do
has_permission_on :users, :to => :index
end
User Model:
class User < ActiveRecord::Base
using_access_control
end
Controller:
@users = User.with_permissions_to(:index)
Let me know if that doesn't work.
제휴하지 않습니다 StackOverflow