我想補充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