Skip to content
Browse files

Explicitly return if resource is already loaded

  • Loading branch information...
1 parent 38d4654 commit 61afb08fa1a9e58413edad165ca4718282df430b @anderslemke committed Feb 5, 2013
Showing with 5 additions and 0 deletions.
  1. +5 −0 lib/cancan/controller_resource.rb
View
5 lib/cancan/controller_resource.rb
@@ -27,6 +27,7 @@ def load_and_authorize_resource
end
def load_resource
+ return if resource_instance_loaded?
unless skip?(:load)
if load_instance?
self.resource_instance ||= load_resource_instance
@@ -160,6 +161,10 @@ def resource_instance
@controller.instance_variable_get("@#{instance_name}") if load_instance?
end
+ def resource_instance_loaded?
+ !@controller.instance_variable_get("@#{instance_name}").nil?
+ end
+
def collection_instance=(instance)
@controller.instance_variable_set("@#{instance_name.to_s.pluralize}", instance)
end

0 comments on commit 61afb08

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