aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2017-01-11 00:03:03 -0500
committerRafael Mendonça França <rafaelmfranca@gmail.com>2017-01-11 00:03:03 -0500
commitf5ec52d4afec986a8f068ac16be6a5dbb4638e76 (patch)
tree7a3cca46b3ed2eaea5246c623194f642d35561c6 /actionpack/lib/action_dispatch
parent2e252852134eb321de975bddd111e19e77da9b27 (diff)
downloadrails-f5ec52d4afec986a8f068ac16be6a5dbb4638e76.tar.gz
rails-f5ec52d4afec986a8f068ac16be6a5dbb4638e76.tar.bz2
rails-f5ec52d4afec986a8f068ac16be6a5dbb4638e76.zip
Make ActionDispatch::Request.parameter_parsers public API
It is the proper way to configure custom parameters parser and it was being recommended in the deprecation for ActionDispatch::ParamsParser. [ci skip]
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r--actionpack/lib/action_dispatch/http/parameters.rb12
1 files changed, 11 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/http/parameters.rb b/actionpack/lib/action_dispatch/http/parameters.rb
index ad4aadacf5..12fc39f1aa 100644
--- a/actionpack/lib/action_dispatch/http/parameters.rb
+++ b/actionpack/lib/action_dispatch/http/parameters.rb
@@ -22,6 +22,7 @@ module ActionDispatch
included do
class << self
+ # Returns the parameter parsers.
attr_reader :parameter_parsers
end
@@ -29,7 +30,16 @@ module ActionDispatch
end
module ClassMethods
- def parameter_parsers=(parsers) # :nodoc:
+ # Configure the parameter parser for a give mime type.
+ #
+ # It accepts a hash where the key is the symbol of the mime type
+ # and the value is a proc.
+ #
+ # original_parsers = ActionDispatch::Request.parameter_parsers
+ # xml_parser = -> (raw_post) { Hash.from_xml(raw_post) || {} }
+ # new_parsers = original_parsers.merge(xml: xml_parser)
+ # ActionDispatch::Request.parameter_parsers = new_parsers
+ def parameter_parsers=(parsers)
@parameter_parsers = parsers.transform_keys { |key| key.respond_to?(:symbol) ? key.symbol : key }
end
end