aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2006-03-07 04:42:13 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2006-03-07 04:42:13 +0000
commitdc4b5cff39a532107354f55f292617ed7250cf6d (patch)
treef97aa0538ebc8aff78bfe931474a805a1f01e9d4 /actionpack/lib/action_controller
parent1c0163e50c789a01d9e96aecf2014e28aa9fef51 (diff)
downloadrails-dc4b5cff39a532107354f55f292617ed7250cf6d.tar.gz
rails-dc4b5cff39a532107354f55f292617ed7250cf6d.tar.bz2
rails-dc4b5cff39a532107354f55f292617ed7250cf6d.zip
XmlSimple _should_ be the default since XmlNode is not compatible with regular parameters -- also known as Why Did My Etech Demo Not Work? [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3806 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_controller')
-rwxr-xr-xactionpack/lib/action_controller/base.rb20
-rwxr-xr-xactionpack/lib/action_controller/cgi_ext/cgi_methods.rb18
2 files changed, 20 insertions, 18 deletions
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
index 8053cc3faf..05c8796f81 100755
--- a/actionpack/lib/action_controller/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -264,24 +264,26 @@ module ActionController #:nodoc:
# The param_parsers hash lets you register handlers wich will process the http body and add parameters to the
# @params hash. These handlers are invoked for post and put requests.
#
- # By default application/xml is enabled. a XmlNode class with the same param name as the root
- # will be instanciated in the @params.
+ # By default application/xml is enabled. A XmlSimple class with the same param name as the root
+ # will be instanciated in the @params. This allows XML requests to mask themselves as regular form submissions,
+ # so you can have one action serve both regular forms and web service requests.
#
- # Example:
+ # Example of doing your own parser for a custom content type:
#
# ActionController::Base.param_parsers['application/atom+xml'] = Proc.new do |data|
# node = REXML::Document.new(post)
# { node.root.name => node.root }
# end
#
- # Note: Up until release 1.1 rails would default to using XmlSimple for such requests. To get the old
- # behavior you can re-register XmlSimple as application/xml handler and enable application/x-yaml like
- # this:
+ # Note: Up until release 1.1 of Rails, Action Controller would default to using XmlSimple configured to discard the
+ # root node for such requests. The new default is to keep the root, such that "<r><name>David</name></r>" results
+ # in params[:r][:name] for "David" instead of params[:name]. To get the old behavior, you can
+ # re-register XmlSimple as application/xml handler and enable application/x-yaml like this:
#
- # ActionController::Base.param_parsers['application/xml'] = :xml_simple
+ # ActionController::Base.param_parsers['application/xml'] =
+ # Proc.new { |data| XmlSimple.xml_in(data, 'ForceArray' => false) }
# ActionController::Base.param_parsers['application/x-yaml'] = :yaml
- #
- @@param_parsers = { 'application/xml' => :xml_node }
+ @@param_parsers = { 'application/xml' => :xml_simple }
cattr_accessor :param_parsers
# Template root determines the base from which template references will be made. So a call to render("test/template")
diff --git a/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb b/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb
index feab806077..3e65e5cb3a 100755
--- a/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb
+++ b/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb
@@ -60,15 +60,15 @@ class CGIMethods #:nodoc:
def self.parse_formatted_request_parameters(format, raw_post_data)
params = case strategy = ActionController::Base.param_parsers[format]
- when Proc
- strategy.call(raw_post_data)
- when :xml_node
- node = XmlNode.from_xml(raw_post_data)
- { node.node_name => node }
- when :xml_simple
- XmlSimple.xml_in(raw_post_data, 'ForceArray' => false)
- when :yaml
- YAML.load(raw_post_data)
+ when Proc
+ strategy.call(raw_post_data)
+ when :xml_simple
+ XmlSimple.xml_in(raw_post_data, 'ForceArray' => false, :keeproot => true)
+ when :yaml
+ YAML.load(raw_post_data)
+ when :xml_node
+ node = XmlNode.from_xml(raw_post_data)
+ { node.node_name => node }
end
params || {}