Complex Form Nesting in Rails - How to create the desired hash / array params output
-
11-11-2019 - |
Question
I'm trying to figure out how to properly handle the params hash so as I dont pass params that should be nested multiple times..
Here is a simplified(removed not-needed info like labels etc) of my html.slim code (using simple_form):
= f.simple_fields_for :room do |r|
- (1..4).each do |room|
= r.input 'adults',:collection => 1..4,:input_html => {:name => "room[adults][]"}
= r.input 'children',:collection => 0..2,:input_html => {:name => "room[children][]"}
- (1..2).each do |child|
= r.input 'child_age',:input_html => {:name => "children[#{child}][ages][]"}
ok this with inputs of 1 room, 1 adult,1 child of age 5 we get params like this :
"room"=>{"adults"=>["1", "1", "1", "1"], "children"=>["1", "0"]}, "children"=>{"1"=>{"ages"=>["5", ""]}, "2"=>{"ages"=>["", ""]}}
what I actually want to have on params is this:
"room"=>{"adults"=>["1", "1", "1", "1"], "children"=>["1"=>["5",""], "0"=>["",""]] }
anyone got any idea on how to do that?
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow