Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Explicitly return on load_resource if resource is already loaded #818

Open
wants to merge 1 commit into from

2 participants

@anderslemke

Hi Ryan,

I've been experiencing some problems using :through. Let's say I have a ressource Thread, which belongs to Forum. In ThreadsController I could then have

load_and_authorize_resource :through => :forum

It seems that the the :through will not respect an already loaded instance variable. If I have

before_filter :manually_set_thread # Which initailizes @thread
load_and_authorize_resource :through => :forum

the load_resource-part will run into problems, because of this part !current_ability.has_block?(authorization_action, resource_class).

Wouldn't it work if load_resource simply does nothing if @thread is already present?

@xhoy

Thanks for your submission! The ryanb/cancan repository has been inactive since Sep 06, 2013.
Since only Ryan himself has commit permissions, the CanCan project is on a standstill.

CanCan has many open issues, including missing support for Rails 4. To keep CanCan alive, an active fork exists at cancancommunity/cancancan. The new gem is cancancan. More info is available at #994.

If your pull request or issue is still applicable, it would be really appreciated if you resubmit it to CanCanCan.

We hope to see you on the other side!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
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
Something went wrong with that request. Please try again.