Permalink
Browse files

build_resource patched to work with namespaced models

  • Loading branch information...
1 parent 9eebeb2 commit 5420cbc15f7877cde936aa22af99191f419a99c1 @inossidabile inossidabile committed Dec 4, 2011
Showing with 8 additions and 2 deletions.
  1. +8 −2 lib/cancan/controller_resource.rb
View
10 lib/cancan/controller_resource.rb
@@ -82,7 +82,7 @@ def load_collection
end
def build_resource
- resource = resource_base.new(@params[name] || {})
+ resource = resource_base.new(@params[namespaced_resource] || {})
resource.send("#{parent_name}=", parent_resource) if @options[:singleton] && parent_resource
initial_attributes.each do |attr_name, value|
resource.send("#{attr_name}=", value)
@@ -92,7 +92,7 @@ def build_resource
def initial_attributes
current_ability.attributes_for(@params[:action].to_sym, resource_class).delete_if do |key, value|
- @params[name] && @params[name].include?(key)
+ @params[namespaced_resource] && @params[namespaced_resource].include?(key)
end
end
@@ -213,6 +213,12 @@ def namespaced_name
name
end
+ def namespaced_resource
+ @name || @params[:controller].sub("Controller", "").underscore.gsub('/', '_').singularize
+ rescue
+ name
+ end
+
def name_from_controller
@params[:controller].sub("Controller", "").underscore.split('/').last.singularize
end

0 comments on commit 5420cbc

Please sign in to comment.