From 2429074075b08b219f4dbbe8f6d08598c1d67878 Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Wed, 15 Mar 2006 21:46:41 +0000 Subject: Underscore dasherized keys in formatted requests git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3878 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/cgi_ext/cgi_methods.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller/cgi_ext/cgi_methods.rb') diff --git a/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb b/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb index f092a41d47..cd70836c6e 100755 --- a/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb +++ b/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb @@ -71,7 +71,7 @@ class CGIMethods #:nodoc: { node.node_name => node } end - params || {} + dasherize_keys(params || {}) rescue Object => e { "exception" => "#{e.message} (#{e.class})", "backtrace" => e.backtrace, "raw_post_data" => raw_post_data, "format" => mime_type } @@ -79,6 +79,18 @@ class CGIMethods #:nodoc: private + def self.dasherize_keys(params) + case params.class.to_s + when "Hash" + params.inject({}) do |h,(k,v)| + h[k.tr("-", "_")] = dasherize_keys(v) + h + end + else + params + end + end + # Splits the given key into several pieces. Example keys are 'name', 'person[name]', # 'person[name][first]', and 'people[]'. In each instance, an Array instance is returned. # 'person[name][first]' produces ['person', 'name', 'first']; 'people[]' produces ['people', ''] -- cgit v1.2.3