Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Namespaces support for controller_resources#build_resource #524

Closed
wants to merge 2 commits into from

3 participants

Boris Staal Jeremy Friesen Anuj Dutta
Boris Staal

The general problem with namespaced models was solved several months ago with help of "namespaced_name". However cancan still tries to get basic name to retrieve data from params[] on :create actions. This is a tiny fix to improve this behavior.

Jeremy Friesen
Collaborator

Both #524 and #528 are doing the same thing.

Anuj Dutta
Collaborator

Hello all, I took the code in #528 (similar to this one) but had specs and created a fresh pull request(#658) incorporating the code in #528 and rebasing it against master. Will close this one.

Anuj Dutta andhapp closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 2 deletions.
  1. +8 −2 lib/cancan/controller_resource.rb
10 lib/cancan/controller_resource.rb
View
@@ -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.