如何将div中的所有数据绑定为rails上的ruby中的子集

时间:2018-04-30 10:40:21

标签: ruby-on-rails ruby ruby-on-rails-5

这里我试图将表单中输入的所有数据保存到数据库中。

目前,我的HTML部分表单如下:

<% LookupValue.laststatus.each do |d| %>
  <div class="row row-margin" id="Counter">
    <div class="col-md-4">
      <%= f.label :"#{d.LookupValueName}:", :class => "col-form-label float-md-right", :for=>"Metric:"+d.LookupValueName%>
    </div>
    <div class="col-md-4">
      <%= f.text_field :"Counter", :class => "form-control tala-count",:id =>"Counter"+d.LookupValueId.to_s, placeholder: "tala Count" %>
    </div>
    <div class="col-md-4">
      <%= f.text_field :"Gantalu", :class => "form-control Gantalu",:id =>"Gantalu"+d.LookupValueId.to_s, placeholder: "Gantalu" %>
    </div>
  </div>
<%end%>

<div class="row row-margin other-metric-row">
  <% if last_LookupValue = LookupValue.status.last %>
    <div class="col-md-4">
      <%= f.text_field :"Gantalu", :class => "form-control other-metric",:id =>last_LookupValue.LookupValueId, placeholder: "Other" %>
    </div>
    <div class="col-md-4">
      <%= f.text_field :"Counter", :class => "form-control tala-count",:id =>"Counter"+last_LookupValue.LookupValueId.to_s, placeholder: "tala Count" %>
    </div>
    <div class="col-md-4">
      <%= f.text_field :"Gantalu", :class => "form-control Gantalu",:id =>"Counter"+last_LookupValue.LookupValueId.to_s, placeholder: "Gantalu" %>
    </div>
  <%end%>
</div>

我的用户界面如下: UI for the partial form

当我将参数传递为&#34; Counter&#34;:params.require(:final).permit(:Counter)我通过控制台看到数据如下:

final[Counter]: Value1
final[Gantalu]: 1
final[Counter]: Value2
final[Gantalu]: 11
final[Counter]: Value3
final[Gantalu]: 111
final[Counter]: Value4
final[Gantalu]: 1111
final[Gantalu]: 
final[Counter]: 
final[Gantalu]:

不确定如何在单个变量下获取所有计数器数据,以便我可以访问在每个文本框中输入的所有数据并访问它们。

提前致谢

0 个答案:

没有答案