cancan_strong_parameters 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -61,17 +61,19 @@ class ActionController::Base
61
61
 
62
62
  def self.filter_strong_params method, actions, keys # :nodoc:
63
63
  hash = keys.extract_options!
64
+ keys.flatten!
64
65
  if hash.present? && keys.present?
65
66
  prepend_before_filter :only => actions do
66
- self.params = params.send method, *keys, hash
67
+ resource_name = self.class.resource_name
68
+ self.params[resource_name] = params[resource_name].send method, *[keys, self.class.attributized(hash)].flatten, hash
67
69
  end
68
70
  elsif hash.present?
69
71
  prepend_before_filter :only => actions do
70
72
  self.params.merge! params.send(method, hash)
71
73
  end
72
74
  else
73
- resource_name = self.to_s.sub("Controller", "").underscore.split('/').last.singularize
74
75
  prepend_before_filter :only => actions do
76
+ resource_name = self.class.resource_name
75
77
  if params.has_key?(resource_name)
76
78
  self.params[resource_name] = params[resource_name].send method, *keys
77
79
  else
@@ -80,6 +82,18 @@ class ActionController::Base
80
82
  end
81
83
  end
82
84
  end
85
+
86
+ def self.resource_name
87
+ self.to_s.sub("Controller", "").underscore.split('/').last.singularize
88
+ end
89
+
90
+ def self.attributized(hash)
91
+ h = {}
92
+ hash.each do |k,v|
93
+ h[:"#{k}_attributes"] = v
94
+ end
95
+ h.keys # @todo Allows all nested values! Insecure, but works
96
+ end
83
97
  end
84
98
 
85
99
  module ActionController
@@ -1,3 +1,3 @@
1
1
  module CancanStrongParameters
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cancan_strong_parameters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-08-28 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cancan
16
- requirement: &70196034599640 !ruby/object:Gem::Requirement
16
+ requirement: &70171147390260 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70196034599640
24
+ version_requirements: *70171147390260
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: strong_parameters
27
- requirement: &70196034599200 !ruby/object:Gem::Requirement
27
+ requirement: &70171147389800 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70196034599200
35
+ version_requirements: *70171147389800
36
36
  description: make CanCan work with strong_parameters
37
37
  email:
38
38
  - me@colinyoung.com