Skip to content
This repository
Browse code

This fixes an odd error I was seeing in development mode when cache_c…

…lasses = 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.
  • Loading branch information...
commit 79180de3722673388c1eb65fc09db5a72fe0b1a8 1 parent f901c36
Michael Halliday authored ryanb committed

Showing 1 changed file with 1 addition and 1 deletion. Show diff stats Hide diff stats

  1. 2  lib/cancan/can_definition.rb
2  lib/cancan/can_definition.rb
@@ -97,7 +97,7 @@ def matches_subject?(subject)
97 97
     end
98 98
 
99 99
     def matches_subject_class?(subject)
100  
-      @subjects.any? { |sub| sub.kind_of?(Module) && (subject.kind_of?(sub) || subject.kind_of?(Module) && subject.ancestors.include?(sub)) }
  100
+      @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)) }
101 101
     end
102 102
 
103 103
     def matches_conditions_hash?(subject, conditions = @conditions)

0 notes on commit 79180de

Please sign in to comment.
Something went wrong with that request. Please try again.