aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
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
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')
-rw-r--r--actionpack/CHANGELOG18
-rwxr-xr-xactionpack/lib/action_controller/base.rb20
-rwxr-xr-xactionpack/lib/action_controller/cgi_ext/cgi_methods.rb18
3 files changed, 30 insertions, 26 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 58c75c44c5..7ebfb81a1a 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -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]
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 || {}