diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2017-03-10 18:09:09 -0500 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2017-03-10 18:10:11 -0500 |
commit | c76190ed76d030452eeee9934f22b2f8bb21405b (patch) | |
tree | 9e1962b2de90688a9a450cfa451bc190482710a3 /actionpack/lib | |
parent | c56c4e4121635ec1221d1a83dd53cedf92ffa283 (diff) | |
parent | 4d7986283653ff4fbd5a82dd273ed9795a0c6a65 (diff) | |
download | rails-c76190ed76d030452eeee9934f22b2f8bb21405b.tar.gz rails-c76190ed76d030452eeee9934f22b2f8bb21405b.tar.bz2 rails-c76190ed76d030452eeee9934f22b2f8bb21405b.zip |
Merge pull request #28355 from Edouard-chin/reversemerge-for-strongparameters
Added `reverse_merge`/`reverse_merge!` to AC::Parameters:
[Rafael Mendonça França + Mitsutaka Mimura]
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_controller/metal/strong_parameters.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb index 9690f0ca28..0217376ab3 100644 --- a/actionpack/lib/action_controller/metal/strong_parameters.rb +++ b/actionpack/lib/action_controller/metal/strong_parameters.rb @@ -660,6 +660,21 @@ module ActionController self end + # Returns a new <tt>ActionController::Parameters</tt> with all keys from + # current hash merged into +other_hash+. + def reverse_merge(other_hash) + new_instance_with_inherited_permitted_status( + other_hash.to_h.merge(@parameters) + ) + end + + # Returns current <tt>ActionController::Parameters</tt> instance with + # current hash merged into +other_hash+. + def reverse_merge!(other_hash) + @parameters.merge!(other_hash.to_h) { |key, left, right| left } + self + end + # This is required by ActiveModel attribute assignment, so that user can # pass +Parameters+ to a mass assignment methods in a model. It should not # matter as we are using +HashWithIndifferentAccess+ internally. |