Ruby on Rails: Access values from form in controller -
how values in form input fields below iterating through ans[n] n = 1...3 in controller?
<input type="text name="ans[1]" value="test 1">
<input type="text name="ans[2]" value="test 2">
<input type="text name="ans[3]" value="test 3">
you can loop on params doing in controller:
#controller params[:ans].each |value| puts value # should print values each input end
if params[:ans]
array of hashes, can access attributes this:
params[:ans].each |answer_attributes| puts answer_attributes['1'] end
Comments
Post a Comment