Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 3806

Show
Ignore:
Timestamp:
03/07/06 04:42:13 (3 years ago)
Author:
david
Message:

XmlSimple _should_ be the default since XmlNode is not compatible with regular parameters -- also known as Why Did My Etech Demo Not Work? [DHH]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r3777 r3806  
    11*SVN* 
    22 
    3 * Added new infrastructure support for REST webservices.  
    4   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 
    5  
    6  ActionController::Base.param_parsers['application/atom+xml'] = Proc.new do |data|  
    7     node = REXML::Document.new(post)  
    8    { node.root.name => node.root } 
    9  end 
     3* 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: 
     4 
     5    # Assign a new param parser to a new content type 
     6    ActionController::Base.param_parsers['application/atom+xml'] = Proc.new do |data|  
     7      node = REXML::Document.new(post)  
     8     { node.root.name => node.root } 
     9    end 
     10 
     11    # Assign the default XmlSimple to a new content type 
     12    ActionController::Base.param_parsers['application/backpack+xml'] = :xml_simple 
    1013  
    11  XmlSimple and Yaml web services were retired, ActionController::Base.param_parsers carries an example which shows how to get this functionality back.  
    12  request.[formatted_post?, xml_post?, yaml_post? and post_format] were all deprecated in favor of request.content_type [Tobias Luetke] 
     14Default 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] 
    1315  
    1416* Fixed Effect.Appear in effects.js to work with floats in Safari #3524, #3813, #3044 [Thomas Fuchs] 
  • trunk/actionpack/lib/action_controller/base.rb

    r3782 r3806  
    265265    # @params hash. These handlers are invoked for post and put requests. 
    266266    # 
    267     # By default application/xml is enabled. a XmlNode class with the same param name as the root  
    268     # will be instanciated in the @params.  
     267    # By default application/xml is enabled. A XmlSimple class with the same param name as the root  
     268    # will be instanciated in the @params. This allows XML requests to mask themselves as regular form submissions, 
     269    # so you can have one action serve both regular forms and web service requests. 
    269270    #  
    270     # Example
     271    # Example of doing your own parser for a custom content type
    271272    # 
    272273    #   ActionController::Base.param_parsers['application/atom+xml'] = Proc.new do |data|  
     
    275276    #   end 
    276277    # 
    277     # Note: Up until release 1.1 rails would default to using XmlSimple for such requests. To get the old  
    278     # behavior you can re-register XmlSimple as application/xml handler and enable application/x-yaml like  
    279     # this: 
     278    # Note: Up until release 1.1 of Rails, Action Controller would default to using XmlSimple configured to discard the  
     279    # root node for such requests. The new default is to keep the root, such that "<r><name>David</name></r>" results 
     280    # in params[:r][:name] for "David" instead of params[:name]. To get the old behavior, you can  
     281    # re-register XmlSimple as application/xml handler and enable application/x-yaml like this: 
    280282    # 
    281     #   ActionController::Base.param_parsers['application/xml'] = :xml_simple 
     283    #   ActionController::Base.param_parsers['application/xml']    =  
     284    #     Proc.new { |data| XmlSimple.xml_in(data, 'ForceArray' => false) } 
    282285    #   ActionController::Base.param_parsers['application/x-yaml'] = :yaml 
    283     # 
    284     @@param_parsers = { 'application/xml' => :xml_node } 
     286    @@param_parsers = { 'application/xml' => :xml_simple } 
    285287    cattr_accessor :param_parsers  
    286288 
  • trunk/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb

    r3778 r3806  
    6161    def self.parse_formatted_request_parameters(format, raw_post_data) 
    6262      params = case strategy = ActionController::Base.param_parsers[format] 
    63       when Proc 
    64         strategy.call(raw_post_data) 
    65       when :xml_nod
    66         node = XmlNode.from_xml(raw_post_data
    67         { node.node_name => node } 
    68       when :xml_simple 
    69         XmlSimple.xml_in(raw_post_data, 'ForceArray' => false) 
    70       when :yaml 
    71         YAML.load(raw_post_data) 
     63        when Proc 
     64          strategy.call(raw_post_data) 
     65        when :xml_simpl
     66          XmlSimple.xml_in(raw_post_data, 'ForceArray' => false, :keeproot => true
     67        when :yaml 
     68          YAML.load(raw_post_data) 
     69        when :xml_node 
     70          node = XmlNode.from_xml(raw_post_data) 
     71          { node.node_name => node } 
    7272      end 
    7373