0
我有一個問題,同時定義用戶和ClassD之間的關聯深入的能力。鐵路cancancan深has_many通過
User < ActiveRecord::Base
has_many :classB
has_many :classC, through classB
has_many :classD, through classB
end
ClassB < ActiveRecord::Base
belongs_to :User
has_many :classC
has_many :classD, through classC
end
ClassC < ActiveRecord::Base
belongs_to ClassC
has_many :ClassD
end
ClassD < ACtiveRecord::Base
belongs_to Class C
end
我如何定義的能力與cancancan,是這樣的:
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new
can :manage, ClassD do |cd|
cd.user_id: user.id
end
end
end