views:

27

answers:

2

I am currently using rturk which give me back my answers in a one dimensional hash as such...

{"answers[125][rating]"=>"5", "answers[126][rating]"=>"5", "commit"=>"Take Survey", "answers[125][rating]"=>"5", "authenticity_token"=>"je0Hx48qKmCzy1zmXCpijYWbl4w92eDMRajWJcVYxe0=", "gender"=>"m", "answers[120][rating]"=>"5", "answers[121][rating]"=>"5", "income"=>"$75,000 to $100,000", "answers[122][rating]"=>"5", "date[year]"=>"1992", "career"=>"Marketer", "answers[123][rating]"=>"5", "answers[124][rating]"=>"5"}

What I would like to do is parse those into a multidimensional hash that I can then just pass as attributes. If I can figure this out I'd probably switch from form_tag back to rails stand object forms.

A: 

Yes, Rack::Utils.parse_nested_query could help you, but you need to convert hash to string:

h = {"answers[125][rating]"=>"5", ...} # your hash
s = h.to_a.collect { |a| a.join('=') }.join('&')
Rack::Utils.parse_nested_query(s)
lest
so I figured out rails added to_query to the Hash class so I don't even need that!
hadees
A: 

Take a look at the Turkee gem (http://github.com/aantix/turkee) as it will do this object mapping for you.