diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2017-04-11 21:56:55 -0400 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2017-04-18 17:33:24 -0400 |
commit | 9f4c2632ef28b9622ffa0eca5d02beea8ec809c0 (patch) | |
tree | 18b38a2187e01d9f02f24d96c67a4e60af8e5827 /actionpack/lib/action_controller | |
parent | fd88ccc905549c61e0e4525fcb68b91d20b9afe9 (diff) | |
download | rails-9f4c2632ef28b9622ffa0eca5d02beea8ec809c0.tar.gz rails-9f4c2632ef28b9622ffa0eca5d02beea8ec809c0.tar.bz2 rails-9f4c2632ef28b9622ffa0eca5d02beea8ec809c0.zip |
Add ActionController::Parameters#to_hash to implict conversion
Now methods that implicit convert objects to a hash will be able to work
without requiring the users to change their implementation.
This method will return a Hash instead of a HashWithIndefirentAccess
to mimic the same implementation of HashWithIndefirentAccess#to_hash.
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r-- | actionpack/lib/action_controller/metal/strong_parameters.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb index b20ad940ea..62c654da03 100644 --- a/actionpack/lib/action_controller/metal/strong_parameters.rb +++ b/actionpack/lib/action_controller/metal/strong_parameters.rb @@ -259,6 +259,22 @@ module ActionController end end + # Returns a safe <tt>Hash</tt> representation of this parameter + # with all unpermitted keys removed. + # + # params = ActionController::Parameters.new({ + # name: 'Senjougahara Hitagi', + # oddity: 'Heavy stone crab' + # }) + # params.to_hash + # # => ActionController::UnfilteredParameters: unable to convert unfiltered parameters to hash + # + # safe_params = params.permit(:name) + # safe_params.to_hash # => {"name"=>"Senjougahara Hitagi"} + def to_hash + to_h.to_hash + end + # Returns an unsafe, unfiltered # <tt>ActiveSupport::HashWithIndifferentAccess</tt> representation of this # parameter. |