Skip to content
This repository
Browse code

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

Fixes Nested Resource Loading
  • Loading branch information...
commit aff8ca60e4e3314ab1f6638dc372409d8ece39a8 2 parents 33e33c5 + d5baed6
Ryan Bates authored
6 lib/cancan/controller_resource.rb
@@ -215,8 +215,12 @@ def resource_params
215 215 end
216 216 end
217 217
  218 + def namespace
  219 + @params[:controller].split("::")[0..-2]
  220 + end
  221 +
218 222 def namespaced_name
219   - @name || @params[:controller].sub("Controller", "").singularize.camelize.constantize
  223 + [namespace, name.camelize].join('::').singularize.camelize.constantize
220 224 rescue NameError
221 225 name
222 226 end
8 spec/cancan/controller_resource_spec.rb
@@ -215,6 +215,14 @@ class Project < ::Project; end
215 215 resource.should_not be_parent
216 216 end
217 217
  218 + it "should have the specified resource_class if 'name' is passed to load_resource" do
  219 + class Section
  220 + end
  221 +
  222 + resource = CanCan::ControllerResource.new(@controller, :section)
  223 + resource.send(:resource_class).should == Section
  224 + end
  225 +
218 226 it "should load parent resource through proper id parameter" do
219 227 project = Project.create!
220 228 @params.merge!(:controller => "categories", :action => "index", :project_id => project.id)

0 comments on commit aff8ca6

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