Class: Rack::NestedParams
- Inherits:
-
Object
- Object
- Rack::NestedParams
- Defined in:
- lib/rack/contrib/nested_params.rb
Overview
Rack middleware for parsing POST/PUT body data into nested parameters
Constant Summary collapse
- CONTENT_TYPE =
'CONTENT_TYPE'.freeze
- POST_BODY =
'rack.input'.freeze
- FORM_INPUT =
'rack.request.form_input'.freeze
- FORM_HASH =
'rack.request.form_hash'.freeze
- FORM_VARS =
'rack.request.form_vars'.freeze
- URL_ENCODED =
supported content type
'application/x-www-form-urlencoded'.freeze
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ NestedParams
constructor
A new instance of NestedParams.
Constructor Details
#initialize(app) ⇒ NestedParams
Returns a new instance of NestedParams.
18 19 20 |
# File 'lib/rack/contrib/nested_params.rb', line 18 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rack/contrib/nested_params.rb', line 22 def call(env) if form_vars = env[FORM_VARS] Rack::Utils.parse_nested_query(form_vars) elsif env[CONTENT_TYPE] == URL_ENCODED post_body = env[POST_BODY] env[FORM_INPUT] = post_body env[FORM_HASH] = Rack::Utils.parse_nested_query(post_body.read) post_body.rewind end @app.call(env) end |