Closed nduitz closed 2 months ago
@nduitz hey! You indeed can use simple_fields_for
to make it work properly:
<%= simple_form_for :bar, html: { class: "quote form" } do |f| %>
<%= f.simple_fields_for 'foo', index: nil do |ff| %>
<%= ff.text_field 'id' %>
<%= ff.text_field 'id' %>
<%= ff.text_field 'id' %>
<%= ff.text_field 'id' %>
<% end %>
<%= f.submit :submit %>
<% end %>
<form class="simple_form quote form" action="/users/new" ...>
<input type="text" name="bar[foo][][id]" id="bar_foo__id">
<input type="text" name="bar[foo][][id]" id="bar_foo__id">
<input type="text" name="bar[foo][][id]" id="bar_foo__id">
<input type="text" name="bar[foo][][id]" id="bar_foo__id">
<input type="submit" name="commit" value="submit" data-disable-with="submit">
</form>
And I believe that's what you have to use if you want to achieve something like that.
Environment
Hey, there.
Rack changed how they parse query parameters which causes the usage of multiple inputs of the same name to generate unparseable query parameters.
Here is a quick example:
The use case here is to create parameters that contain an array in bar which consists of hashes containing id keys.
Current behavior
This produces inputs with names like this:
foo[bar[][id]]
which is no longer supported by rack see https://github.com/rack/rack/issues/2128The resulting parameters look like this:
"foo"=>{"bar["=>{"id"=>{"]"=>"33"}}}
Maybe this is not the intended way to create query params that contain an array containing hashes? I tried using
simple_fields_for
but I could not make it workExpected behavior
I think the names generated by a form like this should follow the conventions mentioned by rails: https://guides.rubyonrails.org/form_helpers.html#understanding-parameter-naming-conventions
thus generating names like this:
foo[bar][][id]
Current Workaround
Simply setting the name manually by adding
input_html: { name: '...' }
BTW:
If anyone could point out where this is implemented I am happy to create a PR but I currently don't have the time to dig this myself.