回答

0
def initialize (user) 
    user ||= User.new # Guest user 
     user.roles.each do |role| 
     role.permissions.each do |p| 
     can :read, p.resource.class_name.to_s.classify.constantize do |subject| 
      p.resource.class_name == subject.id and p.can_read 
     end 
     can :create, p.resource.class_name.to_s.classify.constantize do |subject| 
      p.resource.class_name == subject.id and p.can_create 
     end 
     can :update, p.resource.class_name.to_s.classify.constantize do |subject| 
      p.resource.class_name == subject.id and p.can_update 
     end 
     can :destroy, p.resource.class_name.to_s.classify.constantize do |subject| 
      p.resource.class_name == subject.id and p.can_delete 
     end 
     end 
    end 
end 
0
p.resource.class_name == subject.id and p.can_read 
    end 
    can :create, p.resource.class_name.to_s.classify.constantize do |subject| 
     p.resource.class_name == subject.id and p.can_create 
    end 
    can :update, p.resource.class_name.to_s.classify.constantize do |subject| 
     p.resource.class_name == subject.id and p.can_update