Skip to content

Namespaces support for controller_resources#build_resource #524

Closed
wants to merge 2 commits into from
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
+ namespaced_name.to_s.underscore.gsub('/', '_').singularize
+ rescue
+ name
+ end
+
def name_from_controller
@params[:controller].sub("Controller", "").underscore.split('/').last.singularize
end
Something went wrong with that request. Please try again.