I have had this problem a few times and have come up with this:
= simple_form_for(:lines, url: lines_url) do |f|
- @users.each_with_index do |user, index|
%tr
%td= user.name
- @products.each do |product|
%td
= f.fields_for user do |u|
= u.fields_for index do |u|
= u.fields_for product do |p|
= p.fields_for Line.new do |l|
= l.text_field :quantity
The fields_for index
means that it comes out as lines[user][0][product][line]
etc. , which is how Rails usually deals with submitting multiple objects. The params come in as:
{
"0" => some_data,
"1" => some_other_data
}
which is a bit weird but how it is meant to look. I seem to remember having problems with using this technique with as many levels of nesting as you have, but it should help give you some ideas.