diff options
author | yuuji.yaginuma <yuuji.yaginuma@gmail.com> | 2017-06-19 21:47:00 +0900 |
---|---|---|
committer | yuuji.yaginuma <yuuji.yaginuma@gmail.com> | 2017-06-19 22:06:31 +0900 |
commit | 4cb293af5b6da8c1189ffc5355f5ca372b3c1241 (patch) | |
tree | cd3dff9c8952c7af4e2ea64b6cb24e8ba992ab81 /actionpack | |
parent | 03fa6b2907ae68e0c2cfeb8c3e56c080d7ff99c0 (diff) | |
download | rails-4cb293af5b6da8c1189ffc5355f5ca372b3c1241.tar.gz rails-4cb293af5b6da8c1189ffc5355f5ca372b3c1241.tar.bz2 rails-4cb293af5b6da8c1189ffc5355f5ca372b3c1241.zip |
Fix examples for `AC::Parameters#to_query` [ci skip]
Without `permit`, `AC::Parameters#to_query` raise
`AC::UnfilteredParameters`.
```ruby
params = ActionController::Parameters.new({
name: "David",
nationality: "Danish"
})
params.to_query
# => ActionController::UnfilteredParameters: unable to convert unpermitted parameters to hash
```
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_controller/metal/strong_parameters.rb | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb index cd99e3125f..4a60e2eff2 100644 --- a/actionpack/lib/action_controller/metal/strong_parameters.rb +++ b/actionpack/lib/action_controller/metal/strong_parameters.rb @@ -281,6 +281,10 @@ module ActionController # nationality: "Danish" # }) # params.to_query + # # => ActionController::UnfilteredParameters: unable to convert unpermitted parameters to hash + # + # safe_params = params.permit(:name, :nationality) + # safe_params.to_query # # => "name=David&nationality=Danish" # # An optional namespace can be passed to enclose key names: @@ -289,7 +293,8 @@ module ActionController # name: "David", # nationality: "Danish" # }) - # params.to_query("user") + # safe_params = params.permit(:name, :nationality) + # safe_params.to_query("user") # # => "user%5Bname%5D=David&user%5Bnationality%5D=Danish" # # The string pairs "key=value" that conform the query string |