aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/base.rb
diff options
context:
space:
mode:
authorTobias Lütke <tobias.luetke@gmail.com>2006-03-05 18:59:58 +0000
committerTobias Lütke <tobias.luetke@gmail.com>2006-03-05 18:59:58 +0000
commit03d37a2d68c1940f65d5a65a51ae747955a5b075 (patch)
treeaf6825facc53769e9c16a6cb97a3cc281c125613 /actionpack/lib/action_controller/base.rb
parent4f00c70580e376691bd1d6c1f9d09efbaa7bf9c9 (diff)
downloadrails-03d37a2d68c1940f65d5a65a51ae747955a5b075.tar.gz
rails-03d37a2d68c1940f65d5a65a51ae747955a5b075.tar.bz2
rails-03d37a2d68c1940f65d5a65a51ae747955a5b075.zip
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. M$ ActionController::Base.param_parsers['application/atom+xml'] = Proc.new do |data| node = REXML::Document.new(post) { node.root.name => node.root } end XmlSimple and Yaml web services were retired, ActionController::Base.param_parsers carries an example which shows how to get this functio$ request.[formatted_post?, xml_post?, yaml_post? and post_format] were all deprecated in favor of request.content_type [Tobias Luetke] Closes #4081 git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3777 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_controller/base.rb')
-rwxr-xr-xactionpack/lib/action_controller/base.rb35
1 files changed, 33 insertions, 2 deletions
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
index da27edd68c..ab8cc1802c 100755
--- a/actionpack/lib/action_controller/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -260,10 +260,41 @@ module ActionController #:nodoc:
@@allow_concurrency = false
cattr_accessor :allow_concurrency
+ # Modern REST web services often need to submit complex data to the web application.
+ # 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.
+ #
+ # Example:
+ #
+ # 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:
+ #
+ # ActionController::Base.param_parsers['application/xml'] = Proc.new do |data|
+ # XmlSimple.xml_in(data, 'ForceArray' => false)
+ # end
+ #
+ # ActionController::Base.param_parsers['application/x-yaml'] = Proc.new do |data|
+ # |post| YAML.load(post)
+ # end
+ #
+ @@param_parsers = {
+ 'application/xml' => Proc.new { |post| node = XmlNode.from_xml(post); { node.node_name => node } },
+ }
+ cattr_accessor :param_parsers
+
# Template root determines the base from which template references will be made. So a call to render("test/template")
# will be converted to "#{template_root}/test/template.rhtml".
class_inheritable_accessor :template_root
-
+
# The logger is used for generating information on the action run-time (including benchmarking) if available.
# Can be set to nil for no logging. Compatible with both Ruby's own Logger and Log4r loggers.
cattr_accessor :logger
@@ -302,7 +333,7 @@ module ActionController #:nodoc:
# Returns the name of the action this controller is processing.
attr_accessor :action_name
-
+
class << self
# Factory for the standard create, process loop where the controller is discarded after processing.
def process(request, response) #:nodoc: