我正在尝试添加filter_access_to
,attribute_check: true
但我的模型 ,Assignment
是嵌套的Project
,我想检查当前用户是否已分配给项目,以便他/她可以更新分配(即所有分配,而不仅仅是特定的分配)该项目。
我有下一个权限:
has_permissions_on :assignment do |a|
to :read
if_attribute :user, is { user }
end
在我的控制器中:
filter_access_to :all, require: :manage, context: :assignment, attribute_check: true
问题是我无法访问索引页面,因为它找不到分配的 ID。
我的模型是:
class User < ActiveRecord::Base
has_many :assignments
has_many :projects, through: :assignments
end
class Project < ActiveRecord::Base
has_many :assignments
has_many :users, through: :assignments
end
class Assignment < ActiveRecord::Base
belongs_to :user, inverse_of: :assignments
belongs_to :project, inverse_of: :assignments
end