Module: OptinParsing::ControllerAdditions::ClassMethods
- Defined in:
- lib/optin_parsing/controller_additions.rb
Instance Method Summary collapse
-
#parses(mime_type_or_short_cut, options = {}, &block) ⇒ Object
Declares that you want to parse a specific body type, for this controller and its subclasses You can either pass the symbols
:xml
or:json
or an instance of Mime::Type.
Instance Method Details
#parses(mime_type_or_short_cut, options = {}, &block) ⇒ Object
Declares that you want to parse a specific body type, for this controller and its subclasses You can either pass the symbols :xml
or :json
or an instance of Mime::Type. If you pass a Mime::Type you must also supply a block. The block will be passed the request raw post data and should return a hash of parsed parameter data
You can also supply a hash of options containing the keys :except
or :only
to restrict which actions will be parsed
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/optin_parsing/controller_additions.rb', line 25 def parses mime_type_or_short_cut, ={}, &block case mime_type_or_short_cut when Mime::Type raise ArgumentError, "You must supply a block when specifying a mime type" unless block self.parse_strategies = parse_strategies.merge(mime_type_or_short_cut => [block, ()]) when :xml self.parse_strategies = parse_strategies.merge(Mime::XML => [:xml, ()]) when :json self.parse_strategies = parse_strategies.merge(Mime::JSON => [:json, ()]) end end |