cancan_strong_parameters 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
data/README.md
CHANGED
@@ -20,37 +20,37 @@ class ActionController::Base
|
|
20
20
|
def self.permit_params *keys
|
21
21
|
filter_strong_params :permit, [:create, :update], keys
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
# Like permit_params, but only applies to create action
|
25
25
|
#
|
26
26
|
def self.permit_params_on_create *keys
|
27
27
|
filter_strong_params :permit, :create, keys
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
# Like permit_params, but only applies to update action
|
31
31
|
#
|
32
32
|
def self.permit_params_on_update *keys
|
33
33
|
filter_strong_params :permit, :update, keys
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
# Like permit_params, but marks the params required
|
37
37
|
#
|
38
38
|
def self.require_params *keys
|
39
39
|
filter_strong_params :require, [:create, :update], keys
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
# Like require_params, but only applies to create action
|
43
43
|
#
|
44
|
-
def self.
|
44
|
+
def self.require_params_on_create *keys
|
45
45
|
filter_strong_params :require, :create, keys
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
# Like require_params, but only applies to update action
|
49
49
|
#
|
50
|
-
def self.
|
50
|
+
def self.require_params_on_update *keys
|
51
51
|
filter_strong_params :require, :update, keys
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
# Does a permit! at every level of the params to let everything through
|
55
55
|
#
|
56
56
|
def self.permit_all_params options = {}
|
@@ -58,14 +58,17 @@ class ActionController::Base
|
|
58
58
|
self.params.deep_permit!
|
59
59
|
end
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
def self.filter_strong_params method, actions, keys # :nodoc:
|
63
63
|
hash = keys.extract_options!
|
64
64
|
keys.flatten!
|
65
|
-
|
65
|
+
|
66
|
+
# Handle attributes if permitted attributes are given for nested models
|
67
|
+
if (hash.present? && keys.present?) || (hash.select{|k,v| v.is_a?(Array)} == hash)
|
66
68
|
prepend_before_filter :only => actions do
|
67
69
|
resource_name = self.class.resource_name
|
68
|
-
|
70
|
+
whitelist = self.class.hashified([*keys.flatten, self.class.attributized(hash)])
|
71
|
+
self.params[resource_name] = params[resource_name].send method, whitelist
|
69
72
|
end
|
70
73
|
elsif hash.present?
|
71
74
|
prepend_before_filter :only => actions do
|
@@ -73,7 +76,7 @@ class ActionController::Base
|
|
73
76
|
end
|
74
77
|
else
|
75
78
|
prepend_before_filter :only => actions do
|
76
|
-
resource_name = self.class.resource_name
|
79
|
+
resource_name = self.class.resource_name
|
77
80
|
if params.has_key?(resource_name)
|
78
81
|
self.params[resource_name] = params[resource_name].send method, *keys
|
79
82
|
else
|
@@ -82,17 +85,26 @@ class ActionController::Base
|
|
82
85
|
end
|
83
86
|
end
|
84
87
|
end
|
85
|
-
|
88
|
+
|
86
89
|
def self.resource_name
|
87
90
|
self.to_s.sub("Controller", "").underscore.split('/').last.singularize
|
88
91
|
end
|
89
|
-
|
92
|
+
|
90
93
|
def self.attributized(hash)
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
+
Hash.new.tap do |h|
|
95
|
+
hash.each do |k,v|
|
96
|
+
h[:"#{k}_attributes"] = v
|
97
|
+
end
|
94
98
|
end
|
95
|
-
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.hashified(whitelist)
|
102
|
+
hash = whitelist.extract_options!
|
103
|
+
array = whitelist.dup
|
104
|
+
whitelist = (hash || {})
|
105
|
+
array.map {|v| whitelist[v] = nil }
|
106
|
+
|
107
|
+
whitelist
|
96
108
|
end
|
97
109
|
end
|
98
110
|
|
@@ -110,4 +122,4 @@ module ActionController
|
|
110
122
|
permit!
|
111
123
|
end
|
112
124
|
end
|
113
|
-
end
|
125
|
+
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.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cancan
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: strong_parameters
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,7 +37,12 @@ dependencies:
|
|
32
37
|
version: '0'
|
33
38
|
type: :runtime
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
36
46
|
description: make CanCan work with strong_parameters
|
37
47
|
email:
|
38
48
|
- me@colinyoung.com
|
@@ -69,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
79
|
version: '0'
|
70
80
|
requirements: []
|
71
81
|
rubyforge_project:
|
72
|
-
rubygems_version: 1.8.
|
82
|
+
rubygems_version: 1.8.24
|
73
83
|
signing_key:
|
74
84
|
specification_version: 3
|
75
85
|
summary: make CanCan work with strong_parameters
|