Skip to content

Commit

Permalink
Supporting nested params (post[body]=Something)
Browse files Browse the repository at this point in the history
Signed-off-by: why the lucky stiff <[email protected]>
  • Loading branch information
judofyr authored and why the lucky stiff committed Feb 24, 2009
1 parent 64bd85c commit e7719af
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions lib/camping-unabridged.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ def URL c='/',*a
#
module Base
attr_accessor :input, :cookies, :headers, :body, :status, :root
M = proc { |_, o, n| o.merge(n, &M) }

# Display a view, calling it by its method name +m+. If a <tt>layout</tt>
# method is found in Camping::Views, it will be used to wrap the HTML.
Expand Down Expand Up @@ -412,18 +413,14 @@ def to_a

def initialize(env, m) #:nodoc:
r = @request = Rack::Request.new(@env = env)
@root, @input, @cookies,
@root, p, @cookies,
@headers, @status, @method =
(env.SCRIPT_NAME||'').sub(/\/$/,''),
H[r.params], H[r.cookies],
{}, m =~ /r(\d+)/ ? $1.to_i : 200, m

@input.each do |k, v|
if k[-2..-1] == "[]"
@input[k[0..-3]] = @input.delete(k)
elsif k =~ /(.*)\[([^\]]+)\]$/
(@input[$1] ||= H[])[$2] = @input.delete(k)
end

@input = p.inject(H[]) do |h, (k, v)|
h.merge(k.split(/[\]\[]+/).reverse.inject(v) { |x, i| H[i => x] }, &M)
end
end

Expand Down

0 comments on commit e7719af

Please sign in to comment.