From 79180de3722673388c1eb65fc09db5a72fe0b1a8 Mon Sep 17 00:00:00 2001 From: Michael Halliday Date: Sun, 17 Oct 2010 22:36:40 +0800 Subject: [PATCH] This fixes an odd error I was seeing in development mode when cache_classes = false (the default), specifically when loading an object throught the parent in load_and_authorize_resource. Assume Photo model and User model where user has many photos: @photo = current_user.photos.find(1) # this returns a photo @photo1 = Photo.find(1) @photo.kind_of?(Photo) is not always true for some reason when class_cacheing is false. Where as @photo1.kind_of?(Photo) always appears to be true. Of interesting note, in the above example @photo != @photo1 if kind_of? is false. Very odd. Again, this only appears to be when loading and object through an association. --- lib/cancan/can_definition.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cancan/can_definition.rb b/lib/cancan/can_definition.rb index 1adba11..a7c96d5 100644 --- a/lib/cancan/can_definition.rb +++ b/lib/cancan/can_definition.rb @@ -97,7 +97,7 @@ module CanCan end def matches_subject_class?(subject) - @subjects.any? { |sub| sub.kind_of?(Module) && (subject.kind_of?(sub) || subject.kind_of?(Module) && subject.ancestors.include?(sub)) } + @subjects.any? { |sub| sub.kind_of?(Module) && (subject.kind_of?(sub) || subject.class.to_s == sub.to_s || subject.kind_of?(Module) && subject.ancestors.include?(sub)) } end def matches_conditions_hash?(subject, conditions = @conditions)