【发布时间】:2023-03-18 17:30:01
【问题描述】:
我在定义两次嵌套资源的权限时遇到了一些问题。我有用户 > 公司 > 订单...
我的用户通过协议拥有许多公司。
每个公司都有很多订单,每个订单都属于一个公司。
我的abilities.rb 文件包含以下内容:
elsif user.role? :customer_admin
can [:read, :update], User, :id => user.id
can [:read, :update], Company, :id => user.id
can :read, Company, :users => { :id => user.id }
can :read, Order, :user => { :id => user.id }
end
在我的订单控制器中,我有这个:
load_and_authorize_resource :company
load_and_authorize_resource :order, :through => :company
问题是我似乎无法以 customer_admin 的身份查看订单
希望你能帮忙,再次感谢。
----编辑----
用户.rb
has_and_belongs_to_many :roles
has_many :agreements
has_many :companies, :through => :agreements
公司.rb
has_many :agreements
has_many :users, :through => :agreements
has_many :orders
accepts_nested_attributes_for :orders
order.rb
belongs_to :company
has_many :comments
has_many :tasks
has_many :requirements
has_many :services, :through => :requirements
has_many :servicelevelagreements
has_many :slas, :through => :servicelevelagreements
协议.rb
belongs_to :user
belongs_to :company
希望对你有帮助!!
【问题讨论】:
标签: ruby-on-rails cancan