Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

XmlSimple _should_ be the default since XmlNode is not compatible wit…

…h 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
  • Loading branch information...
commit dc4b5cff39a532107354f55f292617ed7250cf6d 1 parent 1c0163e
David Heinemeier Hansson dhh authored
18 actionpack/CHANGELOG
View
@@ -1,15 +1,17 @@
*SVN*
-* Added new infrastructure support for REST webservices.
- By default application/xml posts are handled by creating a XmlNode object with the same name as the root element of the submitted xml. More handlers can easily be registered like this
+* Added plugin support for parameter parsers, which allows for better support for REST web services. By default, posts submitted with the application/xml content type is handled by creating a XmlSimple hash with the same name as the root element of the submitted xml. More handlers can easily be registered like this:
- ActionController::Base.param_parsers['application/atom+xml'] = Proc.new do |data|
- node = REXML::Document.new(post)
- { node.root.name => node.root }
- end
+ # Assign a new param parser to a new content type
+ ActionController::Base.param_parsers['application/atom+xml'] = Proc.new do |data|
+ node = REXML::Document.new(post)
+ { node.root.name => node.root }
+ end
+
+ # Assign the default XmlSimple to a new content type
+ ActionController::Base.param_parsers['application/backpack+xml'] = :xml_simple
- XmlSimple and Yaml web services were retired, ActionController::Base.param_parsers carries an example which shows how to get this functionality back.
- request.[formatted_post?, xml_post?, yaml_post? and post_format] were all deprecated in favor of request.content_type [Tobias Luetke]
+Default YAML web services were retired, ActionController::Base.param_parsers carries an example which shows how to get this functionality back. As part of this new plugin support, request.[formatted_post?, xml_post?, yaml_post? and post_format] were all deprecated in favor of request.content_type [Tobias Luetke]
* Fixed Effect.Appear in effects.js to work with floats in Safari #3524, #3813, #3044 [Thomas Fuchs]
20 actionpack/lib/action_controller/base.rb
View
@@ -264,24 +264,26 @@ class Base
# 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")
18 actionpack/lib/action_controller/cgi_ext/cgi_methods.rb
View
@@ -60,15 +60,15 @@ def CGIMethods.parse_request_parameters(params)
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 || {}
Please sign in to comment.
Something went wrong with that request. Please try again.