From d5baed6281b4628071f8737090eaaec5168eacbf Mon Sep 17 00:00:00 2001 From: Mark Sim Date: Wed, 5 Oct 2011 11:45:24 -0500 Subject: [PATCH] Fixes Nested Resource Loading --- lib/cancan/controller_resource.rb | 6 +++++- spec/cancan/controller_resource_spec.rb | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/cancan/controller_resource.rb b/lib/cancan/controller_resource.rb index 83a77d1..53cd910 100644 --- a/lib/cancan/controller_resource.rb +++ b/lib/cancan/controller_resource.rb @@ -215,8 +215,12 @@ module CanCan end end + def namespace + @params[:controller].split("::")[0..-2] + end + def namespaced_name - @name || @params[:controller].sub("Controller", "").singularize.camelize.constantize + [namespace, name.camelize].join('::').singularize.camelize.constantize rescue NameError name end diff --git a/spec/cancan/controller_resource_spec.rb b/spec/cancan/controller_resource_spec.rb index eb79324..34f3868 100644 --- a/spec/cancan/controller_resource_spec.rb +++ b/spec/cancan/controller_resource_spec.rb @@ -215,6 +215,14 @@ describe CanCan::ControllerResource do resource.should_not be_parent end + it "should have the specified resource_class if 'name' is passed to load_resource" do + class Section + end + + resource = CanCan::ControllerResource.new(@controller, :section) + resource.send(:resource_class).should == Section + end + it "should load parent resource through proper id parameter" do project = Project.create! @params.merge!(:controller => "categories", :action => "index", :project_id => project.id)