active_params 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +61 -2
- data/lib/active_params/version.rb +1 -1
- data/lib/active_params.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47ecec5d8833f17831a4d8ca416714fc356cd4b8
|
4
|
+
data.tar.gz: 8b0641f760e01cf63a9c7d2c35e16f1039451276
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92a4f7043edb9dae18ac1d9ab9d6f94a902c7e6339364318ee2d0792c9afbeb4744cbfc1f35967d19e8416c25bc81733d125a50444a827010524a3aeb1296940
|
7
|
+
data.tar.gz: 5de694ee1858bac35b7c2548748d2946cd7f3989d2c0589f914fb3e7b4c1727d3930696f2a3aba4a1752e332e2d20cfa74e5350756f0a17c0dcece141e94e5f3
|
data/README.md
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
Stop manually defining `strong_parameters` in each and every controller.
|
4
4
|
|
5
|
-
|
5
|
+
Whatever parameters that was used during `development` mode is considered permitted parameters for `production`. So automatically record them in `development` mode and simply apply `strong_parameters` in production.
|
6
6
|
|
7
|
-
|
7
|
+
aka No more [strong parameters falls!](https://twitter.com/JuanitoFatas/status/746228574592499712) 👌
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
@@ -32,6 +32,65 @@ class ApplicationController < ActionController::Base
|
|
32
32
|
end
|
33
33
|
```
|
34
34
|
|
35
|
+
### Rails.env.development?
|
36
|
+
|
37
|
+
During `development` mode, `active_params` will generate the appropriate strong parameters settings for each param (scoped to the current http method, controller_name and action_name)
|
38
|
+
|
39
|
+
For example, when you submit a form like this
|
40
|
+
|
41
|
+
```
|
42
|
+
Started POST "/users" for 127.0.0.1 at 2016-06-26 00:41:19 +0800
|
43
|
+
Processing by UsersController#create as HTML
|
44
|
+
Parameters: {"utf8"=>"✓", "authenticity_token"=>"...", "user"=>{"name"=>"John", "avatar"=>"Face.png", "photos"=>["Breakfast.png", "Coffee.png"]}, "button"=>""}
|
45
|
+
```
|
46
|
+
|
47
|
+
`active_params` will create or update the `config/active_params.json` file with the settings
|
48
|
+
|
49
|
+
``` json
|
50
|
+
{
|
51
|
+
"POST users/create": {
|
52
|
+
"user": [
|
53
|
+
"avatar",
|
54
|
+
"name",
|
55
|
+
{
|
56
|
+
"photos": [
|
57
|
+
|
58
|
+
]
|
59
|
+
}
|
60
|
+
]
|
61
|
+
}
|
62
|
+
}
|
63
|
+
```
|
64
|
+
|
65
|
+
NOTE: see [the test](https://github.com/choonkeat/active_params/blob/a84e0ab41ee7a522c6c38ee1657cfb68bc4850e9/test/active_params_test.rb#L23-L57) for a more complicated example
|
66
|
+
|
67
|
+
### Rails.env.production? (and other modes)
|
68
|
+
|
69
|
+
In non-development mode, `active_params` will NOT update the `config/active_params.json` file.
|
70
|
+
|
71
|
+
It loads `config/active_params.json` and automatically perform the correct strong parameters setup for each request
|
72
|
+
|
73
|
+
``` ruby
|
74
|
+
params[:user] = params.require(:user).permit(:avatar, :name, photos: [])
|
75
|
+
```
|
76
|
+
|
77
|
+
So, in your controllers, you can simply reference `params[:user]` again!
|
78
|
+
|
79
|
+
``` ruby
|
80
|
+
def create
|
81
|
+
@user = User.new(params[:user])
|
82
|
+
if @user.save
|
83
|
+
redirect_to @user, notice: 'User was successfully created.'
|
84
|
+
else
|
85
|
+
render :new
|
86
|
+
end
|
87
|
+
end
|
88
|
+
```
|
89
|
+
|
90
|
+
### Workflow
|
91
|
+
|
92
|
+
When you create new features for your app & try them out in development mode, `config/active_params.json` will be automatically updated. When you commit your code, include the changes to `config/active_params.json` too.
|
93
|
+
|
35
94
|
## LICENSE
|
36
95
|
|
37
96
|
MIT
|
data/lib/active_params.rb
CHANGED
@@ -9,7 +9,7 @@ module ActiveParams
|
|
9
9
|
current_config[k] = result
|
10
10
|
end
|
11
11
|
end
|
12
|
-
open(ActiveParams.path, "wb") {|f| f.write(JSON.pretty_generate(global_config)
|
12
|
+
open(ActiveParams.path, "wb") {|f| f.write(JSON.pretty_generate(global_config)) }
|
13
13
|
yield
|
14
14
|
end
|
15
15
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_params
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- choonkeat
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|