0
ユーザーとクラスDの間の関連が深くなると能力を定義する際に問題があります。鉄道のカンカンカン深い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