Permalink
Browse files

Merge pull request #650 from andhapp/fix-pull-request-486

Fixes Nested Resource Loading
  • Loading branch information...
2 parents 33e33c5 + d5baed6 commit aff8ca60e4e3314ab1f6638dc372409d8ece39a8 @ryanb committed Jun 19, 2012
Showing with 13 additions and 1 deletion.
  1. +5 −1 lib/cancan/controller_resource.rb
  2. +8 −0 spec/cancan/controller_resource_spec.rb
View
6 lib/cancan/controller_resource.rb
@@ -215,8 +215,12 @@ def resource_params
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
View
8 spec/cancan/controller_resource_spec.rb
@@ -215,6 +215,14 @@ class Project < ::Project; end
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)

0 comments on commit aff8ca6

Please sign in to comment.