Good morning, my doubt arises on an html table in which I am storing the payroll payments of a company, however different models participate in this view, my question is mainly on how to send the tr and td generated in my table to the controller to later be able to separate the different hashes and save them in their corresponding model.
My table is this:
<table id = "mytable">
<thead>
<tr>
<th>Week</th>
<th>Employee</th>
<th>Department</th>
<th>obra</th>
<th class:'totaldias' style="display: true;" id= "jueves">Jueves</th>
<th class:'totaldias' id= "viernes">Viernes</th>
<th class:'totaldias' id= "sabado">Sabado</th>
<th class:'totaldias' id= "domingo">Domingo</th>
<th class:'totaldias' id= "lunes">Lunes</th>
<th class:'totaldias' id= "martes">Martes</th>
<th class:'totaldias' id= "miercoles">Miercoles</th>
<th class:'totaldias' id= "total-dias">Dias trabajados</th>
<th class:'totaldias' id= "vacaciones">Dias vacaciones</th>
<th class:'totaldias' id= "faltas">Faltas</th>
<th><%= link_to "Total Sueldo Bruto","#", id: "mostrarDias", remote: true%></th><!-- 13 -->
<th>Bonos</th>
<th>Flete</th>
<th>Incapacidad</th>
<th>Vacaciones</th>
<th>Finiquito</th>
<th>Total percepciones</th><!-- 19 -->
<th>Caja de Ahorro</th>
<th>Prestamo Aporta</th>
<th>Prestamo</th>
<th>Comida</th>
<th>Uniforme</th>
<th>Pensión Alimenticia</th>
<th>Infonavit</th>
<th>Fonacot</th>
<th>Total retenciones</th><!-- 28 -->
<th>Sueldo fiscal</th>
<th>Total sueldo neto</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @payroll.each do |payroll| %>
<div style= "display: none"><%= ad = ad(payroll.id) %></div>
<tr>
<th><%= payroll.week_id %></th>
<th><%= payroll.employee.fullname %></th>
<th><%= payroll.department.name %></th>
<th><%= payroll.employee_wd.construction_work.name rescue 'base' %></th>
<td class:'totaldias' contenteditable= true onblur=sumDias(getRowIndex(this)) ><%= payroll.employee_wd.jueves rescue 0 %></td>
<td class:'totaldias' contenteditable= true onblur=sumDias(getRowIndex(this)) ><%= payroll.employee_wd.viernes rescue 0%></td>
<td class:'totaldias' contenteditable= true onblur=sumDias(getRowIndex(this)) ><%= payroll.employee_wd.sabado rescue 0 %></td>
<td class:'totaldias' contenteditable= true onblur=sumDias(getRowIndex(this)) ><%= payroll.employee_wd.domingo rescue 0 %></td>
<td class:'totaldias' contenteditable= true onblur=sumDias(getRowIndex(this)) ><%= payroll.employee_wd.lunes rescue 0 %></td>
<td class:'totaldias' contenteditable= true onblur=sumDias(getRowIndex(this)) ><%= payroll.employee_wd.martes rescue 0 %></td>
<td class:'totaldias' contenteditable= true onblur=sumDias(getRowIndex(this)) ><%= payroll.employee_wd.miercoles rescue 0 %></td>
<th class:'totaldias'><%= payroll.dias_trabajados %></th><!-- Dias Trabajados -->
<th class:'totaldias'><%= payroll.dias_vacaciones %></th><!-- Dias de Vacaciones -->
<td class:'totaldias' contenteditable= true ><%= payroll.faltas %></th><!-- Faltas -->
<th class:'totaldias'><%= payroll.total_sueldo_bruto %></th><!-- total sueldo bruto -->
<td contenteditable= true onblur=adSum(getRowIndex(this))><%= ad[0] %></td>
<td contenteditable= true onblur=adSum(getRowIndex(this))><%= ad[1] %></td>
<td contenteditable= true onblur=adSum(getRowIndex(this))><%= ad[2] %></td>
<td contenteditable= true onblur=adSum(getRowIndex(this))><%= ad[3] %></td>
<td contenteditable= true onblur=adSum(getRowIndex(this))><%= ad[4] %></td>
<th><%= payroll.total_percepciones%></th><!-- Total Percepciones -->
<td contenteditable= true onblur=adRest(getRowIndex(this))><%= ad[5] %></td>
<td contenteditable= true onblur=adRest(getRowIndex(this))><%= ad[6] %></td>
<td contenteditable= true onblur=adRest(getRowIndex(this))><%= ad[7] %></td>
<td contenteditable= true onblur=adRest(getRowIndex(this))><%= ad[8] %></td>
<td contenteditable= true onblur=adRest(getRowIndex(this))><%= ad[9] %></td>
<td contenteditable= true onblur=adRest(getRowIndex(this))><%= ad[10] %></td>
<td contenteditable= true onblur=adRest(getRowIndex(this))><%= ad[11] %></td>
<td contenteditable= true onblur=adRest(getRowIndex(this))><%= ad[12] %></td>
<th><%= payroll.total_retenciones %></th><!-- total retenciones -->
<th><%= payroll.sueldo_fiscal %></th><!-- Sueldo fiscal -->
<th><%= payroll.total_sueldo_neto %></th><!--total sueldo neto -->
<td>
<input type="Submit" />
</tr>
<% end %>
</tbody>
</table>
Or if there is a gem that can be used to perform this action, I am new to rails and I really have no idea how to perform this action.
I thank you in advance for your help.
Edited:
In this case, what I want is to send the data contained in the td contained in the tbody, in this case I do not know how to send this information, it had occurred to me to make a form_for per row and a for_form that contains all of them with the submit that sends the information, but the truth I do not know what is the best way to do it. In itself what I want is to send the data that is entered into the table and in turn the information contained in the variable payroll.
And I mean with the hash of hashes that I want to send all the lines contained in the tbody with a single click on 'save', since each row would be a record to be made of payroll.
Edited
Modify my table as follows:
<tbody>
<%form_tag({controller: "payrolls", action: "create"}, method: "post", class: "nifty_form", remote: true) do%>
<% @payroll.each do |payroll| %>
<div style= "display: none"><%= ad = ad(payroll.id) %></div>
<tr>
<td><%=(:week_id, payroll.week_id) %></th>
<td><%= text_field_tag(:employee_name, payroll.employee.fullname) %></th>
<td><%=text_field_tag(:department_name, payroll.department.name) %></th>
<td onblur=sumDias(getRowIndex(this)) ><%= text_field_tag(:jueves, payroll.employee_wd.jueves)%></td>
<td onblur=sumDias(getRowIndex(this)) ><%= text_field_tag(:viernes, payroll.employee_wd.viernes)%></td>
<td onblur=sumDias(getRowIndex(this)) ><%= text_field_tag(:sabado, payroll.employee_wd.sabado) %></td>
<td onblur=sumDias(getRowIndex(this)) ><%=text_field_tag(:domingo, payroll.employee_wd.domingo) %></td>
<td onblur=sumDias(getRowIndex(this)) ><%= text_field_tag(:lunes,payroll.employee_wd.lunes) %></td>
<td onblur=sumDias(getRowIndex(this)) ><%= text_field_tag(:martes, payroll.employee_wd.martes)%></td>
<td onblur=sumDias(getRowIndex(this)) ><%= text_field_tag(:miercoles, payroll.employee_wd.miercoles) %></td>
<th><%= text_field_tag(:dias_trabajados, payroll.dias_trabajados) %></th><!-- Dias Trabajados -->
<th><%=text_field_tag(:dias_vacaciones, payroll.dias_vacaciones) %></th><!-- Dias de Vacaciones -->
<td><%=text_field_tag(:faltas, payroll.faltas) %></th><!-- Faltas -->
<th><%= text_field_tag(:total_sueldo_bruto, payroll.total_sueldo_bruto) %></th><!-- total sueldo bruto -->
<td onblur=adSum(getRowIndex(this))><%=text_field_tag(:bonos, ad[0]) %></td>
<td onblur=adSum(getRowIndex(this))><%=text_field_tag(:fletes, ad[1])%></td>
<td onblur=adSum(getRowIndex(this))><%=text_field_tag(:jueves, ad[2] )%></td>
<td onblur=adSum(getRowIndex(this))><%=text_field_tag(:incapacidad, ad[3]) %></td>
<td onblur=adSum(getRowIndex(this))><%=text_field_tag(:finiquito, ad[4]) %></td>
<td><%=text_field_tag(:total_percepciones, payroll.total_percepciones)%></th><!-- Total Percepciones -->
<td onblur=adRest(getRowIndex(this))><%=text_field_tag(:caja_ahorro, ad[5]) %></td>
<td onblur=adRest(getRowIndex(this))><%=text_field_tag(:prestamo_aporta, ad[6]) %></td>
<td onblur=adRest(getRowIndex(this))><%=text_field_tag(:prestamo, ad[7] )%></td>
<td onblur=adRest(getRowIndex(this))><%=text_field_tag(:comida, ad[8]) %></td>
<td onblur=adRest(getRowIndex(this))><%= text_field_tag(:uniforme, ad[9]) %></td>
<td onblur=adRest(getRowIndex(this))><%= text_field_tag(:pension_alimenticia, ad[10] )%></td>
<td onblur=adRest(getRowIndex(this))><%= text_field_tag(:infonavit, ad[11]) %></td>
<td onblur=adRest(getRowIndex(this))><%= text_field_tag(:fonacot, ad[12]) %></td>
<td><%=text_field_tag(:total_retenciones, payroll.total_retenciones) %></th><!-- total retenciones -->
<td><%=text_field_tag(:sueldo_fiscal, payroll.sueldo_fiscal) %></th><!-- Sueldo fiscal -->
<td><%= text_field_tag(:total_sueldo_neto, payroll.total_sueldo_neto) %></th><!--total sueldo neto -->
<% end %>
<%= submit_tag("guardar") %>
<% end %>
</tbody>
However, it shows me the page with no data or form to fill out, only the headings of the table since those are outside the. I hope you can help me.