Class: Rack::NestedParams

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(app) ⇒ NestedParams

Returns a new instance of NestedParams.



16
17
18
# File 'lib/rack/contrib/nested_params.rb', line 16

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rack/contrib/nested_params.rb', line 20

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 if post_body.respond_to?(:rewind)
  end
  @app.call(env)
end